Skip to content

Commit 9dac126

Browse files
committed
Fix MSVC build issues
MSVC fails when there is ambiguity (multiple options) around implicit type conversion operators. Make ConstString's conversion operator to string_view explicit to avoid ambiguity with one to StringRef and remove an unused local variable that MSVC also fails on. Cherrypick commit llvm@34a0f37
1 parent 3bbc45d commit 9dac126

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lldb/include/lldb/Utility/ConstString.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ class ConstString {
184184
// Implicitly convert \class ConstString instances to \class StringRef.
185185
operator llvm::StringRef() const { return GetStringRef(); }
186186

187-
// Implicitly convert \class ConstString instances to \class std::string_view.
188-
operator std::string_view() const {
187+
// Explicitly convert \class ConstString instances to \class std::string_view.
188+
explicit operator std::string_view() const {
189189
return std::string_view(m_string, GetLength());
190190
}
191191

@@ -435,6 +435,11 @@ class ConstString {
435435
/// Stream the string value \a str to the stream \a s
436436
Stream &operator<<(Stream &s, ConstString str);
437437

438+
inline std::string &operator+=(std::string &str, const lldb_private::ConstString &s) {
439+
str += llvm::StringRef(s).str();
440+
return str;
441+
}
442+
438443
} // namespace lldb_private
439444

440445
namespace llvm {

lldb/source/Core/Mangled.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void Mangled::SetValue(ConstString name) {
138138
}
139139

140140
// Local helpers for different demangling implementations.
141-
static char *GetMSVCDemangledStr(std::string_view M) {
141+
static char *GetMSVCDemangledStr(llvm::StringRef M) {
142142
char *demangled_cstr = llvm::microsoftDemangle(
143143
M, nullptr, nullptr,
144144
llvm::MSDemangleFlags(
@@ -182,27 +182,29 @@ static char *GetItaniumDemangledStr(const char *M) {
182182
return demangled_cstr;
183183
}
184184

185-
static char *GetRustV0DemangledStr(std::string_view M) {
185+
static char *GetRustV0DemangledStr(llvm::StringRef M) {
186186
char *demangled_cstr = llvm::rustDemangle(M);
187187

188188
if (Log *log = GetLog(LLDBLog::Demangle)) {
189189
if (demangled_cstr && demangled_cstr[0])
190190
LLDB_LOG(log, "demangled rustv0: {0} -> \"{1}\"", M, demangled_cstr);
191191
else
192-
LLDB_LOG(log, "demangled rustv0: {0} -> error: failed to demangle", M);
192+
LLDB_LOG(log, "demangled rustv0: {0} -> error: failed to demangle",
193+
static_cast<std::string_view>(M));
193194
}
194195

195196
return demangled_cstr;
196197
}
197198

198-
static char *GetDLangDemangledStr(std::string_view M) {
199+
static char *GetDLangDemangledStr(llvm::StringRef M) {
199200
char *demangled_cstr = llvm::dlangDemangle(M);
200201

201202
if (Log *log = GetLog(LLDBLog::Demangle)) {
202203
if (demangled_cstr && demangled_cstr[0])
203204
LLDB_LOG(log, "demangled dlang: {0} -> \"{1}\"", M, demangled_cstr);
204205
else
205-
LLDB_LOG(log, "demangled dlang: {0} -> error: failed to demangle", M);
206+
LLDB_LOG(log, "demangled dlang: {0} -> error: failed to demangle",
207+
static_cast<std::string_view>(M));
206208
}
207209

208210
return demangled_cstr;

lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ TEST_F(SymbolFilePDBTests, TestTypedefs) {
528528
SymbolFilePDB *symfile =
529529
static_cast<SymbolFilePDB *>(module->GetSymbolFile());
530530
llvm::pdb::IPDBSession &session = symfile->GetPDBSession();
531-
TypeMap results;
532531

533532
const char *TypedefsToCheck[] = {"ClassTypedef", "NSClassTypedef",
534533
"FuncPointerTypedef",

0 commit comments

Comments
 (0)