Author: Alexandre Ganea Date: 2021-01-14T08:35:38-05:00 New Revision: 6abbba3fca9fdf8d31f74800a7ddb40b103ae6e3
URL: https://github.com/llvm/llvm-project/commit/6abbba3fca9fdf8d31f74800a7ddb40b103ae6e3 DIFF: https://github.com/llvm/llvm-project/commit/6abbba3fca9fdf8d31f74800a7ddb40b103ae6e3.diff LOG: Revert "Fix llvm::Optional build breaks in MSVC using std::is_trivially_copyable" This reverts commit 854f0984f0b7ab9a9a541a4bcda7ea173e4113d3. This breaks compilation with clang-cl on Windows, while in a MSVC 16.8 cmd.exe. This also breaks PPC: http://lab.llvm.org:8011/#/builders/93/builds/1435 And: https://reviews.llvm.org/D93510#2497737 Added: Modified: llvm/include/llvm/ADT/Optional.h llvm/unittests/ADT/OptionalTest.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index 820e586ff7dd..daa9ee627fa9 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -33,12 +33,7 @@ namespace optional_detail { struct in_place_t {}; /// Storage for any type. -template <typename T, bool = (std::is_trivially_copy_constructible<T>::value && - std::is_trivially_copy_assignable<T>::value && - (std::is_trivially_move_constructible<T>::value || - !std::is_move_constructible<T>::value) && - (std::is_trivially_move_assignable<T>::value || - !std::is_move_assignable<T>::value))> +template <typename T, bool = is_trivially_copyable<T>::value> class OptionalStorage { union { char empty; diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp index 235b834887d1..c7fa796a2d7f 100644 --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -390,127 +390,6 @@ TEST(OptionalTest, ImmovableEmplace) { EXPECT_EQ(0u, Immovable::Destructions); } -// Craft a class which is_trivially_copyable, but not -// is_trivially_copy_constructible. -struct NonTCopy { - NonTCopy() = default; - - // Delete the volatile copy constructor to engage the "rule of 3" and delete - // any unspecified copy assignment or constructor. - NonTCopy(volatile NonTCopy const &) = delete; - - // Leave the non-volatile default copy constructor unspecified (deleted by - // rule of 3) - - // This template can serve as the copy constructor, but isn't chosen - // by =default in a class with a 'NonTCopy' member. - template <typename Self = NonTCopy> - NonTCopy(Self const &Other) : Val(Other.Val) {} - - NonTCopy &operator=(NonTCopy const &) = default; - - int Val{0}; -}; - -#if defined(_MSC_VER) && _MSC_VER >= 1927 -// Currently only true on recent MSVC releases. -static_assert(std::is_trivially_copyable<NonTCopy>::value, - "Expect NonTCopy to be trivially copyable"); - -static_assert(!std::is_trivially_copy_constructible<NonTCopy>::value, - "Expect NonTCopy not to be trivially copy constructible."); -#endif // defined(_MSC_VER) && _MSC_VER >= 1927 - -TEST(OptionalTest, DeletedCopyConstructor) { - - // Expect compile to fail if 'trivial' version of - // optional_detail::OptionalStorage is chosen. - using NonTCopyOptT = Optional<NonTCopy>; - NonTCopyOptT NonTCopy1; - - // Check that the Optional can be copy constructed. - NonTCopyOptT NonTCopy2{NonTCopy1}; - - // Check that the Optional can be copy assigned. - NonTCopy1 = NonTCopy2; -} - -// Craft a class which is_trivially_copyable, but not -// is_trivially_copy_assignable. -class NonTAssign { -public: - NonTAssign() = default; - NonTAssign(NonTAssign const &) = default; - - // Delete the volatile copy assignment to engage the "rule of 3" and delete - // any unspecified copy assignment or constructor. - NonTAssign &operator=(volatile NonTAssign const &) = delete; - - // Leave the non-volatile default copy assignment unspecified (deleted by rule - // of 3). - - // This template can serve as the copy assignment, but isn't chosen - // by =default in a class with a 'NonTAssign' member. - template <typename Self = NonTAssign> - NonTAssign &operator=(Self const &Other) { - A = Other.A; - return *this; - } - - int A{0}; -}; - -#if defined(_MSC_VER) && _MSC_VER >= 1927 -// Currently only true on recent MSVC releases. -static_assert(std::is_trivially_copyable<NonTAssign>::value, - "Expect NonTAssign to be trivially copyable"); - -static_assert(!std::is_trivially_copy_assignable<NonTAssign>::value, - "Expect NonTAssign not to be trivially assignable."); -#endif // defined(_MSC_VER) && _MSC_VER >= 1927 - -TEST(OptionalTest, DeletedCopyAssignment) { - - // Expect compile to fail if 'trivial' version of - // optional_detail::OptionalStorage is chosen. - using NonTAssignOptT = Optional<NonTAssign>; - NonTAssignOptT NonTAssign1; - - // Check that the Optional can be copy constructed. - NonTAssignOptT NonTAssign2{NonTAssign1}; - - // Check that the Optional can be copy assigned. - NonTAssign1 = NonTAssign2; -} - -struct NoTMove { - NoTMove() = default; - NoTMove(NoTMove const &) = default; - NoTMove &operator=(NoTMove const &) = default; - - // Delete move constructor / assignment. Compiler should fall-back to the - // trivial copy constructor / assignment in the trivial OptionalStorage - // specialization. - NoTMove(NoTMove &&) = delete; - NoTMove &operator=(NoTMove &&) = delete; - - int Val{0}; -}; - -TEST(OptionalTest, DeletedMoveConstructor) { - using NoTMoveOptT = Optional<NoTMove>; - - NoTMoveOptT NonTMove1; - NoTMoveOptT NonTMove2{std::move(NonTMove1)}; - - NonTMove1 = std::move(NonTMove2); - - static_assert( - std::is_trivially_copyable<NoTMoveOptT>::value, - "Expect Optional<NoTMove> to still use the trivial specialization " - "of OptionalStorage despite the deleted move constructor / assignment."); -} - #if LLVM_HAS_RVALUE_REFERENCE_THIS TEST(OptionalTest, MoveGetValueOr) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits