OSDN Git Service

Use LLVM_EXPLICIT instead of a function pointer as bool.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 16 Jan 2014 23:37:23 +0000 (23:37 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 16 Jan 2014 23:37:23 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199437 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ErrorOr.h
unittests/Support/ErrorOrTest.cpp

index 543f507..39fec3b 100644 (file)
@@ -169,12 +169,9 @@ public:
       getStorage()->~storage_type();
   }
 
-  typedef void (*unspecified_bool_type)();
-  static void unspecified_bool_true() {}
-
   /// \brief Return false if there is an error.
-  operator unspecified_bool_type() const {
-    return HasError ? 0 : unspecified_bool_true;
+  LLVM_EXPLICIT operator bool() const {
+    return !HasError;
   }
 
   reference get() { return *getStorage(); }
index 8a5b068..7a0c31f 100644 (file)
@@ -20,7 +20,9 @@ ErrorOr<int> t2() { return errc::invalid_argument; }
 
 TEST(ErrorOr, SimpleValue) {
   ErrorOr<int> a = t1();
-  EXPECT_TRUE(a);
+  // FIXME: This is probably a bug in gtest. EXPECT_TRUE should expand to
+  // include the !! to make it friendly to explicit bool operators.
+  EXPECT_TRUE(!!a);
   EXPECT_EQ(1, *a);
 
   ErrorOr<int> b = a;