[Support] Add a conditionally defined default constructor (available on MSVC
authorLang Hames <lhames@gmail.com>
Tue, 30 Aug 2016 05:32:41 +0000 (05:32 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 30 Aug 2016 05:32:41 +0000 (05:32 +0000)
only) for Expected<T> so that it can interoperate with MSVC's std::future
implementation.

MSVC 2013's std::future implementation requires the wrapped type to be default
constructible.

Hopefully this will fix the bot breakage in
http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9937 .

llvm-svn: 280058

llvm/include/llvm/Support/Error.h

index afd2660..bd488e4 100644 (file)
@@ -629,6 +629,27 @@ private:
   typedef const typename std::remove_reference<T>::type *const_pointer;
 
 public:
+
+#ifdef _MSC_VER
+  // WARNING: This constructor should *never* be called in user code.
+  // It is provided under MSVC only so that Expected can be used
+  // with MSVC's <future> header, which requires types to be default
+  // constructible.
+  //
+  // FIXME; Kill this as soon as MSVC's <future> implementation no longer
+  // requires types to be default constructible.
+  Expected()
+      : HasError(true)
+#ifndef NDEBUG
+        ,
+        Checked(true)
+#endif // NDEBUG
+  {
+    new (getErrorStorage()) Error();
+    !!*getErrorStorage();
+  }
+#endif // _MSC_VER
+
   /// Create an Expected<T> error value from the given Error.
   Expected(Error Err)
       : HasError(true)