Index: lldb/include/lldb/Core/Mangled.h =================================================================== --- lldb/include/lldb/Core/Mangled.h +++ lldb/include/lldb/Core/Mangled.h @@ -72,10 +72,10 @@ return !(*this == rhs); } - /// Convert to pointer operator. + /// Convert to bool operator. /// - /// This allows code to check a Mangled object to see if it contains a valid - /// mangled name using code such as: + /// This allows code to check any Mangled objects to see if they contain + /// anything valid using code such as: /// /// \code /// Mangled mangled(...); @@ -84,14 +84,14 @@ /// \endcode /// /// \return - /// A pointer to this object if either the mangled or unmangled - /// name is set, NULL otherwise. - operator void *() const; + /// Returns \b true if either the mangled or unmangled name is set, \b + /// false otherwise. + explicit operator bool() const; /// Logical NOT operator. /// - /// This allows code to check a Mangled object to see if it contains an - /// empty mangled name using code such as: + /// This allows code to check any Mangled objects to see if they are invalid + /// using code such as: /// /// \code /// Mangled mangled(...); Index: lldb/source/Core/Mangled.cpp =================================================================== --- lldb/source/Core/Mangled.cpp +++ lldb/source/Core/Mangled.cpp @@ -70,15 +70,13 @@ SetValue(ConstString(name)); } -// Convert to pointer operator. This allows code to check any Mangled objects +// Convert to bool operator. This allows code to check any Mangled objects // to see if they contain anything valid using code such as: // // Mangled mangled(...); // if (mangled) // { ... -Mangled::operator void *() const { - return (m_mangled) ? const_cast(this) : nullptr; -} +Mangled::operator bool() const { return m_mangled || m_demangled; } // Logical NOT operator. This allows code to check any Mangled objects to see // if they are invalid using code such as: @@ -86,7 +84,7 @@ // Mangled mangled(...); // if (!file_spec) // { ... -bool Mangled::operator!() const { return !m_mangled; } +bool Mangled::operator!() const { return !m_mangled && !m_demangled; } // Clear the mangled and demangled values. void Mangled::Clear() { Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2140,7 +2140,8 @@ llvm::StringRef basename; llvm::StringRef context; - bool name_is_mangled = (bool)Mangled(name); + bool name_is_mangled = Mangled::GetManglingScheme(name.GetStringRef()) != + Mangled::eManglingSchemeNone; if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name.GetCString(), context, basename)) Index: lldb/unittests/Core/MangledTest.cpp =================================================================== --- lldb/unittests/Core/MangledTest.cpp +++ lldb/unittests/Core/MangledTest.cpp @@ -89,6 +89,39 @@ EXPECT_STREQ("", the_demangled.GetCString()); } +TEST(MangledTest, BoolConversionOperator) { + { + ConstString MangledName("_ZN1a1b1cIiiiEEvm"); + Mangled TheMangled(MangledName); + EXPECT_EQ(true, bool(TheMangled)); + } + { + ConstString UnmangledName("puts"); + Mangled TheMangled(UnmangledName); + EXPECT_EQ(true, bool(TheMangled)); + } + { + Mangled TheMangled{}; + EXPECT_EQ(false, bool(TheMangled)); + } +} + +TEST(MangledTest, LogicalNotOperator) { + { + ConstString MangledName("_ZN1a1b1cIiiiEEvm"); + Mangled TheMangled(MangledName); + EXPECT_EQ(false, !TheMangled); + } + { + ConstString UnmangledName("puts"); + Mangled TheMangled(UnmangledName); + EXPECT_EQ(false, !TheMangled); + } + { + Mangled TheMangled{}; + EXPECT_EQ(true, !TheMangled); + } +} TEST(MangledTest, NameIndexes_FindFunctionSymbols) { SubsystemRAII