[clang-rename] Add the USR of incomplete decl to the USRSet.

Summary:
This fixes a clangd rename issue, which is missing the reference of
an incomplete specialization.

Unfortunately, I didn't reproduce this issue in clang-rename, I guess
the input `FoundDecl` of AdditionalUSRFinder is different in clangd vs
clang-rename, clang-rename uses the underlying CXXRecordDecl of the
ClassTemplateDecl, which is fixed in 5d862c042b;
while clangd-rename uses the ClassTemplateDecl.

Reviewers: kbobyrev

Reviewed By: kbobyrev

Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74829
This commit is contained in:
Haojian Wu 2020-02-25 16:32:22 +01:00
parent a82ffe9d93
commit e6d0bad843
2 changed files with 12 additions and 3 deletions

View File

@ -202,6 +202,13 @@ TEST(RenameTest, WithinFileRename) {
}
)cpp",
// Incomplete class specializations
R"cpp(
template <typename T>
class [[Fo^o]] {};
void func([[Foo]]<int>);
)cpp",
// Template class instantiations.
R"cpp(
template <typename T>

View File

@ -126,12 +126,14 @@ private:
addUSRsOfCtorDtors(TemplateDecl->getTemplatedDecl());
}
void addUSRsOfCtorDtors(const CXXRecordDecl *RecordDecl) {
RecordDecl = RecordDecl->getDefinition();
void addUSRsOfCtorDtors(const CXXRecordDecl *RD) {
const auto* RecordDecl = RD->getDefinition();
// Skip if the CXXRecordDecl doesn't have definition.
if (!RecordDecl)
if (!RecordDecl) {
USRSet.insert(getUSRForDecl(RD));
return;
}
for (const auto *CtorDecl : RecordDecl->ctors())
USRSet.insert(getUSRForDecl(CtorDecl));