From: Serge Guelton Date: Sat, 16 Feb 2019 09:47:23 +0000 (+0000) Subject: Revert r354199: Make Optional Trivially Copyable when T is trivially copyable X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a99830ce5abfd18e4962504ae08be42ef13d1e90;p=llvm Revert r354199: Make Optional Trivially Copyable when T is trivially copyable git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354200 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h index ab83b67b11b..25a3185064f 100644 --- a/include/llvm/ADT/Optional.h +++ b/include/llvm/ADT/Optional.h @@ -108,59 +108,6 @@ template ::value> struct OptionalSto return reinterpret_cast(storage.buffer); } }; -template struct OptionalStorage { - AlignedCharArrayUnion storage; - bool hasVal = false; - - OptionalStorage() = default; - - OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); } - OptionalStorage(const OptionalStorage &O) = default; - OptionalStorage(T &&y) : hasVal(true) { - new (storage.buffer) T(std::forward(y)); - } - OptionalStorage(OptionalStorage &&O) = default; - - OptionalStorage &operator=(T &&y) { - if (hasVal) - *getPointer() = std::move(y); - else { - new (storage.buffer) T(std::move(y)); - hasVal = true; - } - return *this; - } - OptionalStorage &operator=(OptionalStorage &&O) = default; - - OptionalStorage &operator=(const T &y) { - if (hasVal) - *getPointer() = y; - else { - new (storage.buffer) T(y); - hasVal = true; - } - return *this; - } - OptionalStorage &operator=(const OptionalStorage &O) = default; - - ~OptionalStorage() = default; - - void reset() { - if (hasVal) { - (*getPointer()).~T(); - hasVal = false; - } - } - - T *getPointer() { - assert(hasVal); - return reinterpret_cast(storage.buffer); - } - const T *getPointer() const { - assert(hasVal); - return reinterpret_cast(storage.buffer); - } -}; } // namespace optional_detail diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp index 015fcf38981..98adaccca96 100644 --- a/unittests/ADT/OptionalTest.cpp +++ b/unittests/ADT/OptionalTest.cpp @@ -14,15 +14,8 @@ #include - using namespace llvm; -static_assert(llvm::is_trivially_copyable>::value, - "trivially copyable"); - -static_assert(llvm::is_trivially_copyable>>::value, - "trivially copyable"); - namespace { struct NonDefaultConstructible {