r181908 - [analyzer] Put back DefaultBool's implicit conversion to bool.

Jordan Rose jordan_rose at apple.com
Wed May 15 11:08:15 PDT 2013


Author: jrose
Date: Wed May 15 13:08:15 2013
New Revision: 181908

URL: http://llvm.org/viewvc/llvm-project?rev=181908&view=rev
Log:
[analyzer] Put back DefaultBool's implicit conversion to bool.

DefaultBool is basically just "bool with a default constructor", so it
really should implicitly convert to bool. In fact, it should convert to
bool&, so that it could be passed to functions that take bools by reference.

This time, mark the operator bool& as implicit to promise that it's
deliberate.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h?rev=181908&r1=181907&r2=181908&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h Wed May 15 13:08:15 2013
@@ -502,10 +502,14 @@ struct ImplicitNullDerefEvent {
 };
 
 /// \brief A helper class which wraps a boolean value set to false by default.
+///
+/// This class should behave exactly like 'bool' except that it doesn't need to
+/// be explicitly initialized.
 struct DefaultBool {
   bool val;
   DefaultBool() : val(false) {}
-  LLVM_EXPLICIT operator bool() const { return val; }
+  /*implicit*/ operator bool&() { return val; }
+  /*implicit*/ operator const bool&() const { return val; }
   DefaultBool &operator=(bool b) { val = b; return *this; }
 };
 





More information about the cfe-commits mailing list