From 36bc95bc6c3ef4ae23145483b0715585c7621060 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 19 Apr 2023 17:47:09 -0700 Subject: [PATCH] Basic: add a workaround for VS2019 When building with MSVC, we seem to be hitting a crash in the compiler. The crash seems to originate from the use of the `member_constructible` predicate being used in the `std::enable_if`. Use a local variable instead to avoid this issue. This problem is already resolved in VS2022, and hopefully we will be switching to that soon. --- include/swift/Basic/TaggedUnion.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/include/swift/Basic/TaggedUnion.h b/include/swift/Basic/TaggedUnion.h index 556ccf07f7de5..9d95215dbbd5e 100644 --- a/include/swift/Basic/TaggedUnion.h +++ b/include/swift/Basic/TaggedUnion.h @@ -57,22 +57,24 @@ class TaggedUnionBase + static constexpr const bool constructible = + TaggedUnionImpl::is_member_constructible(); + public: /// Construct the union with a value of the given type, which must /// (ignoring references) be one of the declared members of the union. template TaggedUnionBase(T &&value, - typename std::enable_if< - TaggedUnionImpl::is_member_constructible(), - TaggedUnionImpl::Empty>::type = {}) { + typename std::enable_if, + TaggedUnionImpl::Empty>::type = {}) { using TargetType = TaggedUnionImpl::simplify_member_type; TheKind = StorageType::template kindForMember(); Storage.template emplace(TheKind, std::forward(value)); } template - typename std::enable_if(), - TaggedUnionBase &>::type + typename std::enable_if, TaggedUnionBase &>::type operator=(T &&value) { using TargetType = TaggedUnionImpl::simplify_member_type; TheKind = StorageType::template kindForMember(); @@ -155,12 +157,15 @@ class TaggedUnionBase + static constexpr const bool constructible = + TaggedUnionImpl::is_member_constructible(); + public: template TaggedUnionBase(T &&value, - typename std::enable_if< - TaggedUnionImpl::is_member_constructible(), - TaggedUnionImpl::Empty>::type = {}) + typename std::enable_if, + TaggedUnionImpl::Empty>::type = {}) : super(std::forward(value)) {} // We want to either define or delete all the special members. @@ -236,12 +241,15 @@ class TaggedUnionBase return super::StorageType::template kindForMember(); } + template + static constexpr const bool constructible = + TaggedUnionImpl::is_member_constructible(); + public: template TaggedUnionBase(T &&value, - typename std::enable_if< - TaggedUnionImpl::is_member_constructible(), - TaggedUnionImpl::Empty>::type = {}) + typename std::enable_if, + TaggedUnionImpl::Empty>::type = {}) : super(std::forward(value)) {} /// Construct the union in the empty state.