From: Jordan Rose Date: Wed, 15 May 2013 18:08:15 +0000 (+0000) Subject: [analyzer] Put back DefaultBool's implicit conversion to bool. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cce70c7c5f0f4c1a41658fbed845f8b3a565c99c;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181908 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/Checker.h b/include/clang/StaticAnalyzer/Core/Checker.h index d56f8e9c1d..219e99cfd4 100644 --- a/include/clang/StaticAnalyzer/Core/Checker.h +++ b/include/clang/StaticAnalyzer/Core/Checker.h @@ -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; } };