diff options
author | Serge Guelton <sguelton@redhat.com> | 2019-02-18 12:07:12 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@redhat.com> | 2019-02-18 12:07:12 +0000 |
commit | 6e0b562bf6e0e94e3ea6a755a9917b2725fd604d (patch) | |
tree | 5c1a6690c80fbcd1c43ae9d9ebdc21191f762f04 /llvm/unittests/ADT | |
parent | 515e7cdec04a4f77defecbc9453e11159b635ddf (diff) | |
download | bcm5719-llvm-6e0b562bf6e0e94e3ea6a755a9917b2725fd604d.tar.gz bcm5719-llvm-6e0b562bf6e0e94e3ea6a755a9917b2725fd604d.zip |
[NFC] Make Optional<T> trivially copyable when T is trivially copyable
This is a follow-up to r354246 and a reimplementation of https://reviews.llvm.org/D57097?id=186600
that should not trigger any UB thanks to the use of an union.
This may still be subject to the problem solved by std::launder, but I'm unsure how it interacts whith union.
/me plans to revert if this triggers any relevant bot failure. At least this validates in Release mode with
clang 6.0.1 and gcc 4.8.5.
llvm-svn: 354264
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r-- | llvm/unittests/ADT/OptionalTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp index 98adaccca96..1f26c101183 100644 --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -14,8 +14,15 @@ #include <array> + using namespace llvm; +static_assert(is_trivially_copyable<Optional<int>>::value, + "trivially copyable"); + +static_assert(is_trivially_copyable<Optional<std::array<int, 3>>>::value, + "trivially copyable"); + namespace { struct NonDefaultConstructible { @@ -45,6 +52,10 @@ unsigned NonDefaultConstructible::CopyConstructions = 0; unsigned NonDefaultConstructible::Destructions = 0; unsigned NonDefaultConstructible::CopyAssignments = 0; +static_assert( + !is_trivially_copyable<Optional<NonDefaultConstructible>>::value, + "not trivially copyable"); + // Test fixture class OptionalTest : public testing::Test { }; @@ -203,6 +214,10 @@ struct MultiArgConstructor { }; unsigned MultiArgConstructor::Destructions = 0; +static_assert( + !is_trivially_copyable<Optional<MultiArgConstructor>>::value, + "not trivially copyable"); + TEST_F(OptionalTest, Emplace) { MultiArgConstructor::ResetCounts(); Optional<MultiArgConstructor> A; @@ -250,6 +265,9 @@ unsigned MoveOnly::MoveConstructions = 0; unsigned MoveOnly::Destructions = 0; unsigned MoveOnly::MoveAssignments = 0; +static_assert(!is_trivially_copyable<Optional<MoveOnly>>::value, + "not trivially copyable"); + TEST_F(OptionalTest, MoveOnlyNull) { MoveOnly::ResetCounts(); Optional<MoveOnly> O; @@ -351,6 +369,9 @@ private: unsigned Immovable::Constructions = 0; unsigned Immovable::Destructions = 0; +static_assert(!is_trivially_copyable<Optional<Immovable>>::value, + "not trivially copyable"); + TEST_F(OptionalTest, ImmovableEmplace) { Optional<Immovable> A; Immovable::ResetCounts(); |