[Support] Fix a segfault in llvm::Expected.
authorLang Hames <lhames@gmail.com>
Thu, 3 Nov 2016 22:01:47 +0000 (22:01 +0000)
committerLang Hames <lhames@gmail.com>
Thu, 3 Nov 2016 22:01:47 +0000 (22:01 +0000)
This fixes a mismatch between the declared error_type and the type used with
the placement new that initializes the field.

Patch by Yichao Yu.

llvm-svn: 285970

llvm/include/llvm/Support/Error.h

index 0f9b326038513f074e7886c52391007530fb8510..cdd46a84b5c13ef5b03931cae68ccd34b6b9ee78 100644 (file)
@@ -147,7 +147,7 @@ class LLVM_NODISCARD Error {
 
   // Expected<T> needs to be able to steal the payload when constructed from an
   // error.
-  template <typename T> class Expected;
+  template <typename T> friend class Expected;
 
 public:
   /// Create a success value. Prefer using 'Error::success()' for readability
@@ -642,7 +642,7 @@ public:
 
   {
     assert(Err && "Cannot create Expected<T> from Error success value.");
-    new (getErrorStorage()) Error(std::move(Err));
+    new (getErrorStorage()) error_type(Err.takePayload());
   }
 
   /// Create an Expected<T> success value from the given OtherT value, which