[llvm] r199437 - Use LLVM_EXPLICIT instead of a function pointer as bool.
Rafael Espindola
rafael.espindola at gmail.com
Thu Jan 16 15:37:23 PST 2014
Author: rafael
Date: Thu Jan 16 17:37:23 2014
New Revision: 199437
URL: http://llvm.org/viewvc/llvm-project?rev=199437&view=rev
Log:
Use LLVM_EXPLICIT instead of a function pointer as bool.
Modified:
llvm/trunk/include/llvm/Support/ErrorOr.h
llvm/trunk/unittests/Support/ErrorOrTest.cpp
Modified: llvm/trunk/include/llvm/Support/ErrorOr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorOr.h?rev=199437&r1=199436&r2=199437&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ErrorOr.h (original)
+++ llvm/trunk/include/llvm/Support/ErrorOr.h Thu Jan 16 17:37:23 2014
@@ -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(); }
Modified: llvm/trunk/unittests/Support/ErrorOrTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ErrorOrTest.cpp?rev=199437&r1=199436&r2=199437&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ErrorOrTest.cpp (original)
+++ llvm/trunk/unittests/Support/ErrorOrTest.cpp Thu Jan 16 17:37:23 2014
@@ -20,7 +20,9 @@ ErrorOr<int> t2() { return errc::invalid
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;
More information about the llvm-commits
mailing list