Skip to content

Commit

Permalink
[clangd] Fix an assertion failure in NamedDecl::getName during the pr…
Browse files Browse the repository at this point in the history
…epareRename

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
  • Loading branch information
hokein committed Jul 14, 2023
1 parent 8338354 commit 5649b24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/refactor/Rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ const NamedDecl *lookupSiblingWithinEnclosingScope(ASTContext &Ctx,
return nullptr;
for (const auto &Child : DS->getDeclGroup())
if (const auto *ND = dyn_cast<NamedDecl>(Child))
if (ND != &RenamedDecl && ND->getName() == Name)
if (ND != &RenamedDecl && ND->getDeclName().isIdentifier() &&
ND->getName() == Name)
return ND;
return nullptr;
};
Expand Down
9 changes: 9 additions & 0 deletions clang-tools-extra/clangd/unittests/RenameTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,15 @@ TEST(RenameTest, Renameable) {
using ns::^foo;
)cpp",
"there are multiple symbols at the given location", !HeaderFile},

{R"cpp(
void test() {
// no crash
using namespace std;
int [[V^ar]];
}
)cpp",
nullptr, !HeaderFile},
};

for (const auto& Case : Cases) {
Expand Down

0 comments on commit 5649b24

Please sign in to comment.