[Lldb-commits] [lldb] r191984 - Made all other "operator bool"s explicit and ensured

Sean Callanan scallanan at apple.com
Fri Oct 4 14:35:29 PDT 2013


Author: spyffe
Date: Fri Oct  4 16:35:29 2013
New Revision: 191984

URL: http://llvm.org/viewvc/llvm-project?rev=191984&view=rev
Log:
Made all other "operator bool"s explicit and ensured
that all clients use them explicitly.  This will hopefully
prevent any future confusion where things get cast to types
we don't expect.

<rdar://problem/15146458>

Modified:
    lldb/trunk/include/lldb/Core/ModuleSpec.h
    lldb/trunk/include/lldb/Host/FileSpec.h
    lldb/trunk/include/lldb/Interpreter/CommandObject.h
    lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h
    lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/include/lldb/Symbol/ClangASTType.h
    lldb/trunk/include/lldb/Symbol/ClangNamespaceDecl.h
    lldb/trunk/include/lldb/Utility/SharingPtr.h
    lldb/trunk/source/API/SBFileSpec.cpp
    lldb/trunk/source/API/SBModuleSpec.cpp
    lldb/trunk/source/Commands/CommandObjectRegister.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: lldb/trunk/include/lldb/Core/ModuleSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleSpec.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleSpec.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleSpec.h Fri Oct  4 16:35:29 2013
@@ -288,7 +288,7 @@ public:
     }
 
     
-    operator bool () const
+    explicit operator bool () const
     {
         if (m_file)
             return true;

Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Fri Oct  4 16:35:29 2013
@@ -177,7 +177,7 @@ public:
     ///     A pointer to this object if either the directory or filename
     ///     is valid, NULL otherwise.
     //------------------------------------------------------------------
-    operator bool() const;
+    explicit operator bool() const;
 
     //------------------------------------------------------------------
     /// Logical NOT operator.

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Fri Oct  4 16:35:29 2013
@@ -42,7 +42,7 @@ public:
             return (*help_callback)();
         }
         
-        operator bool() const
+        explicit operator bool() const
         {
             return (help_callback != NULL);
         }

Modified: lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionValueBoolean.h Fri Oct  4 16:35:29 2013
@@ -92,7 +92,7 @@ public:
     ///     /b True this object contains a valid namespace decl, \b 
     ///     false otherwise.
     //------------------------------------------------------------------
-    operator bool() const
+    explicit operator bool() const
     {
         return m_current_value;
     }

Modified: lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h (original)
+++ lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h Fri Oct  4 16:35:29 2013
@@ -105,7 +105,7 @@ namespace lldb_private {
         PythonString
         Str ();
         
-        operator bool () const
+        explicit operator bool () const
         {
             return m_py_obj != NULL;
         }

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Fri Oct  4 16:35:29 2013
@@ -41,7 +41,7 @@ public:
         return m_object;
     }
     
-    operator bool ()
+    explicit operator bool ()
     {
         return m_object != NULL;
     }

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Fri Oct  4 16:35:29 2013
@@ -282,7 +282,7 @@ private:
             Py_XINCREF(m_object);
         }
         
-        operator bool ()
+        explicit operator bool ()
         {
             return m_object && m_object != Py_None;
         }
@@ -351,7 +351,7 @@ private:
     public:
         PythonInputReaderManager (ScriptInterpreterPython *interpreter);
         
-        operator bool()
+        explicit operator bool()
         {
             return m_error;
         }

Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Fri Oct  4 16:35:29 2013
@@ -98,7 +98,7 @@ public:
     // Tests
     //----------------------------------------------------------------------
 
-    operator bool () const
+    explicit operator bool () const
     {
         return m_type != NULL && m_ast != NULL;
     }

Modified: lldb/trunk/include/lldb/Symbol/ClangNamespaceDecl.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangNamespaceDecl.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangNamespaceDecl.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangNamespaceDecl.h Fri Oct  4 16:35:29 2013
@@ -62,7 +62,7 @@ public:
     ///     /b True this object contains a valid namespace decl, \b 
     ///     false otherwise.
     //------------------------------------------------------------------
-    operator bool() const
+    explicit operator bool() const
     {
         return m_ast != NULL && m_namespace_decl != NULL;
     }

Modified: lldb/trunk/include/lldb/Utility/SharingPtr.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/SharingPtr.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/SharingPtr.h (original)
+++ lldb/trunk/include/lldb/Utility/SharingPtr.h Fri Oct  4 16:35:29 2013
@@ -714,7 +714,7 @@ public:
         return ptr_; 
     }
     
-    operator bool() const
+    explicit operator bool() const
     {
         return ptr_ != 0;
     }

Modified: lldb/trunk/source/API/SBFileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFileSpec.cpp?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFileSpec.cpp (original)
+++ lldb/trunk/source/API/SBFileSpec.cpp Fri Oct  4 16:35:29 2013
@@ -61,7 +61,7 @@ SBFileSpec::operator = (const SBFileSpec
 bool
 SBFileSpec::IsValid() const
 {
-    return *m_opaque_ap;
+    return m_opaque_ap->operator bool();
 }
 
 bool

Modified: lldb/trunk/source/API/SBModuleSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModuleSpec.cpp?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModuleSpec.cpp (original)
+++ lldb/trunk/source/API/SBModuleSpec.cpp Fri Oct  4 16:35:29 2013
@@ -44,7 +44,7 @@ SBModuleSpec::~SBModuleSpec ()
 bool
 SBModuleSpec::IsValid () const
 {
-    return *m_opaque_ap;
+    return m_opaque_ap->operator bool();
 }
 
 void

Modified: lldb/trunk/source/Commands/CommandObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectRegister.cpp?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectRegister.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectRegister.cpp Fri Oct  4 16:35:29 2013
@@ -98,7 +98,7 @@ public:
             {
                 strm.Indent ();
 
-                bool prefix_with_altname = m_command_options.alternate_name;
+                bool prefix_with_altname = (bool)m_command_options.alternate_name;
                 bool prefix_with_name = !prefix_with_altname;
                 reg_value.Dump(&strm, reg_info, prefix_with_name, prefix_with_altname, m_format_options.GetFormat(), 8);
                 if ((reg_info->encoding == eEncodingUint) || (reg_info->encoding == eEncodingSint))

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Fri Oct  4 16:35:29 2013
@@ -1900,12 +1900,12 @@ FormatPromptRecurse
                                                 if (var_name_begin[0] == 'n' || var_name_begin[5] == 'f')
                                                 {
                                                     format_file_spec.GetFilename() = exe_module->GetFileSpec().GetFilename();
-                                                    var_success = format_file_spec;
+                                                    var_success = (bool)format_file_spec;
                                                 }
                                                 else
                                                 {
                                                     format_file_spec = exe_module->GetFileSpec();
-                                                    var_success = format_file_spec;
+                                                    var_success = (bool)format_file_spec;
                                                 }
                                             }
                                         }
@@ -2065,12 +2065,12 @@ FormatPromptRecurse
                                             if (IsToken (var_name_begin, "basename}"))
                                             {
                                                 format_file_spec.GetFilename() = module->GetFileSpec().GetFilename();
-                                                var_success = format_file_spec;
+                                                var_success = (bool)format_file_spec;
                                             }
                                             else if (IsToken (var_name_begin, "fullpath}"))
                                             {
                                                 format_file_spec = module->GetFileSpec();
-                                                var_success = format_file_spec;
+                                                var_success = (bool)format_file_spec;
                                             }
                                         }
                                     }
@@ -2089,12 +2089,12 @@ FormatPromptRecurse
                                     if (IsToken (var_name_begin, "basename}"))
                                     {
                                         format_file_spec.GetFilename() = sc->comp_unit->GetFilename();
-                                        var_success = format_file_spec;
+                                        var_success = (bool)format_file_spec;
                                     }
                                     else if (IsToken (var_name_begin, "fullpath}"))
                                     {
                                         format_file_spec = *sc->comp_unit;
-                                        var_success = format_file_spec;
+                                        var_success = (bool)format_file_spec;
                                     }
                                 }
                             }
@@ -2353,12 +2353,12 @@ FormatPromptRecurse
                                         if (IsToken (var_name_begin, "basename}"))
                                         {
                                             format_file_spec.GetFilename() = sc->line_entry.file.GetFilename();
-                                            var_success = format_file_spec;
+                                            var_success = (bool)format_file_spec;
                                         }
                                         else if (IsToken (var_name_begin, "fullpath}"))
                                         {
                                             format_file_spec = sc->line_entry.file;
-                                            var_success = format_file_spec;
+                                            var_success = (bool)format_file_spec;
                                         }
                                     }
                                     else if (IsTokenWithFormat (var_name_begin, "number", token_format, "%" PRIu64, exe_ctx, sc))

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h Fri Oct  4 16:35:29 2013
@@ -54,7 +54,7 @@ public:
         }
 
         // Test operator
-        operator bool() const
+        explicit operator bool() const
         {
             return tag != 0;
         }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=191984&r1=191983&r2=191984&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Oct  4 16:35:29 2013
@@ -2625,7 +2625,7 @@ SymbolFileDWARF::ResolveClangOpaqueTypeD
             }
         }
 
-        return clang_type;
+        return (bool)clang_type;
 
     case DW_TAG_enumeration_type:
         clang_type.StartTagDeclarationDefinition ();
@@ -2637,7 +2637,7 @@ SymbolFileDWARF::ResolveClangOpaqueTypeD
             ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
         }
         clang_type.CompleteTagDeclarationDefinition ();
-        return clang_type;
+        return (bool)clang_type;
 
     default:
         assert(false && "not a forward clang type decl!");





More information about the lldb-commits mailing list