From 91ecc30daa8f2a1632e7c55b471db3fb9e0189d4 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Fri, 15 Feb 2019 16:12:46 +0000 Subject: [PATCH] Revert r354137 - OptionalStorage implementation for trivial type, take III This still fails on some random platform, and I fail to reproduce the issue. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354142 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/Optional.h | 52 ++----------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h index 55bbfc5f100..25a3185064f 100644 --- a/include/llvm/ADT/Optional.h +++ b/include/llvm/ADT/Optional.h @@ -109,54 +109,6 @@ template ::value> struct OptionalSto } }; -template struct OptionalStorage { - struct empty_type {}; - union { - empty_type empty; - T value; - }; - bool hasVal = false; - - OptionalStorage() : empty{} {} - - OptionalStorage(const T &y) : hasVal(true) { - new ((void*)std::addressof(value)) T(y); - } - OptionalStorage(const OptionalStorage &O) = default; - OptionalStorage(T &&y) : hasVal(true) { - new ((void*)std::addressof(value)) T(std::move(y)); - } - - OptionalStorage(OptionalStorage &&O) = default; - - OptionalStorage &operator=(T &&y) { - hasVal = true; - new ((void*)std::addressof(value)) T(std::move(y)); - return *this; - } - OptionalStorage &operator=(OptionalStorage &&O) = default; - - OptionalStorage &operator=(const T &y) { - hasVal = true; - new ((void*)std::addressof(value)) T(y); - return *this; - } - OptionalStorage &operator=(const OptionalStorage &O) = default; - - ~OptionalStorage() = default; - - T *getPointer() { - assert(hasVal); - return &value; - } - const T *getPointer() const { - assert(hasVal); - return &value; - } - - void reset() { hasVal = false; } -}; - } // namespace optional_detail template class Optional { @@ -201,11 +153,11 @@ public: const T *getPointer() const { assert(Storage.hasVal); - return Storage.getPointer(); + return reinterpret_cast(Storage.storage.buffer); } T *getPointer() { assert(Storage.hasVal); - return Storage.getPointer(); + return reinterpret_cast(Storage.storage.buffer); } const T &getValue() const LLVM_LVALUE_FUNCTION { return *getPointer(); } T &getValue() LLVM_LVALUE_FUNCTION { return *getPointer(); } -- 2.50.1