From: Haojian Wu Date: Tue, 25 Feb 2020 15:32:22 +0000 (+0100) Subject: [clang-rename] Add the USR of incomplete decl to the USRSet. X-Git-Tag: llvmorg-12-init~13695 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6d0bad843c4c84bb762cf93a56c5bdd5cc535c0;p=platform%2Fupstream%2Fllvm.git [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 https://github.com/llvm/llvm-project/commit/5d862c042b52ae2aad37471d0b83b6c678a520e3; 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 --- diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp index aa08be4..82930eb 100644 --- a/clang-tools-extra/clangd/unittests/RenameTests.cpp +++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -202,6 +202,13 @@ TEST(RenameTest, WithinFileRename) { } )cpp", + // Incomplete class specializations + R"cpp( + template + class [[Fo^o]] {}; + void func([[Foo]]); + )cpp", + // Template class instantiations. R"cpp( template diff --git a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp index a17b880..43dc32e 100644 --- a/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ b/clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -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));