[llvm] r285970 - [Support] Fix a segfault in llvm::Expected.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 15:01:48 PDT 2016


Author: lhames
Date: Thu Nov  3 17:01:47 2016
New Revision: 285970

URL: http://llvm.org/viewvc/llvm-project?rev=285970&view=rev
Log:
[Support] Fix a segfault in llvm::Expected.

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.


Modified:
    llvm/trunk/include/llvm/Support/Error.h

Modified: llvm/trunk/include/llvm/Support/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=285970&r1=285969&r2=285970&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Error.h (original)
+++ llvm/trunk/include/llvm/Support/Error.h Thu Nov  3 17:01:47 2016
@@ -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




More information about the llvm-commits mailing list