diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index cdbf2e353241..2af59865b8ff 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -34,12 +34,12 @@ namespace optional_detail { /// Storage for any type. // // The specialization condition intentionally uses -// llvm::is_trivially_copy_constructible instead of -// std::is_trivially_copy_constructible. GCC versions prior to 7.4 may -// instantiate the copy constructor of `T` when -// std::is_trivially_copy_constructible is instantiated. This causes -// compilation to fail if we query the trivially copy constructible property of -// a class which is not copy constructible. +// llvm::is_trivially_{copy/move}_constructible instead of +// std::is_trivially_{copy/move}_constructible. GCC versions prior to 7.4 may +// instantiate the copy/move constructor of `T` when +// std::is_trivially_{copy/move}_constructible is instantiated. This causes +// compilation to fail if we query the trivially copy/move constructible +// property of a class which is not copy/move constructible. // // The current implementation of OptionalStorage insists that in order to use // the trivial specialization, the value_type must be trivially copy @@ -50,12 +50,13 @@ namespace optional_detail { // // The move constructible / assignable conditions emulate the remaining behavior // of std::is_trivially_copyable. -template ::value && - std::is_trivially_copy_assignable::value && - (std::is_trivially_move_constructible::value || - !std::is_move_constructible::value) && - (std::is_trivially_move_assignable::value || - !std::is_move_assignable::value))> +template ::value && + std::is_trivially_copy_assignable::value && + (llvm::is_trivially_move_constructible::value || + !std::is_move_constructible::value) && + (std::is_trivially_move_assignable::value || + !std::is_move_assignable::value))> class OptionalStorage { union { char empty; diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp index debeb78e8fab..b664792f2dfb 100644 --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -805,4 +805,15 @@ TEST(OptionalTest, HashValue) { EXPECT_EQ(hash_value(B), hash_value(I)); } +struct NotTriviallyCopyable { + NotTriviallyCopyable(); // Constructor out-of-line. + virtual ~NotTriviallyCopyable() = default; + Optional MO; +}; + +TEST(OptionalTest, GCCIsTriviallyMoveConstructibleCompat) { + Optional V; + EXPECT_FALSE(V); +} + } // end anonymous namespace