Skip to content

Commit 29b579e

Browse files
committed
[cxx-interop] Do not crash when diagnosing cycles for C++ operators
C++ operator functions are `NamedDecl`s, but they don't have a trivial name, and calling `getName` results in an assertion failure. This was discovered during C++ interop adoption in SwiftCompilerSources. ``` Assertion failed: (Name.isIdentifier() && "Name is not a simple identifier"), function getName, file Decl.h, line 277. ... /Volumes/Projects/swift/llvm-project/clang/include/clang/AST/DependentDiagnostic.h:150:8: importing 'clang::DeclContext::ddiag_iterator::operator==' ```
1 parent 8165806 commit 29b579e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8193,9 +8193,13 @@ ClangImporter::Implementation::importDeclForDeclContext(
81938193
if (!contextDeclsWarnedAbout.insert(contextDecl).second)
81948194
return nullptr;
81958195

8196-
auto getDeclName = [](const clang::Decl *D) -> StringRef {
8197-
if (auto ND = dyn_cast<clang::NamedDecl>(D))
8198-
return ND->getName();
8196+
auto getDeclName = [](const clang::Decl *D) -> std::string {
8197+
if (auto ND = dyn_cast<clang::NamedDecl>(D)) {
8198+
std::string name;
8199+
llvm::raw_string_ostream os(name);
8200+
ND->printName(os);
8201+
return name;
8202+
}
81998203
return "<anonymous>";
82008204
};
82018205

0 commit comments

Comments
 (0)