Optional specialization for trivially copyable types, part2
authorSerge Guelton <sguelton@redhat.com>
Thu, 14 Feb 2019 19:41:44 +0000 (19:41 +0000)
committerSerge Guelton <sguelton@redhat.com>
Thu, 14 Feb 2019 19:41:44 +0000 (19:41 +0000)
llvm-svn: 354055

llvm/include/llvm/ADT/Optional.h

index c628df9..f7d35c7 100644 (file)
@@ -116,7 +116,9 @@ template <typename T> struct OptionalStorage<T, true> {
 
   OptionalStorage() = default;
 
-  OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); }
+  OptionalStorage(const T &y) : hasVal(true) {
+    std::memcpy(storage.buffer, reinterpret_cast<char const *>(&y), sizeof(T));
+  }
   OptionalStorage(const OptionalStorage &O) = default;
   OptionalStorage(T &&y) : hasVal(true) {
     std::memcpy(storage.buffer, reinterpret_cast<char*>(&y), sizeof(T));