Skip to content

Commit 5649b24

Browse files
committed
[clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename
getName method required to be called on a simple-identifier NamedDecl, otherwise it will trigger an assertion. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D153617
1 parent 8338354 commit 5649b24

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ const NamedDecl *lookupSiblingWithinEnclosingScope(ASTContext &Ctx,
332332
return nullptr;
333333
for (const auto &Child : DS->getDeclGroup())
334334
if (const auto *ND = dyn_cast<NamedDecl>(Child))
335-
if (ND != &RenamedDecl && ND->getName() == Name)
335+
if (ND != &RenamedDecl && ND->getDeclName().isIdentifier() &&
336+
ND->getName() == Name)
336337
return ND;
337338
return nullptr;
338339
};

clang-tools-extra/clangd/unittests/RenameTests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,15 @@ TEST(RenameTest, Renameable) {
11291129
using ns::^foo;
11301130
)cpp",
11311131
"there are multiple symbols at the given location", !HeaderFile},
1132+
1133+
{R"cpp(
1134+
void test() {
1135+
// no crash
1136+
using namespace std;
1137+
int [[V^ar]];
1138+
}
1139+
)cpp",
1140+
nullptr, !HeaderFile},
11321141
};
11331142

11341143
for (const auto& Case : Cases) {

0 commit comments

Comments
 (0)