[PATCH] D74216: [clang-rename] Fix the missing template constructors.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 00:24:04 PST 2020
hokein updated this revision to Diff 243752.
hokein marked 3 inline comments as done.
hokein added a comment.
address comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74216/new/
https://reviews.llvm.org/D74216
Files:
clang-tools-extra/clangd/unittests/RenameTests.cpp
clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
clang/test/clang-rename/Ctor.cpp
Index: clang/test/clang-rename/Ctor.cpp
===================================================================
--- clang/test/clang-rename/Ctor.cpp
+++ clang/test/clang-rename/Ctor.cpp
@@ -5,10 +5,23 @@
Foo::Foo() /* Test 2 */ {} // CHECK: Bar::Bar() /* Test 2 */ {}
+
+class Foo2 { /* Test 3 */ // CHECK: class Bar2 {
+public:
+ template <typename T>
+ Foo2(); // CHECK: Bar2();
+
+ template <typename T>
+ Foo2(Foo2 &); // CHECK: Bar2(Bar2 &);
+};
+
+
// Test 1.
// RUN: clang-rename -offset=62 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=116 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=187 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s
// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===================================================================
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -135,6 +135,13 @@
for (const auto *CtorDecl : RecordDecl->ctors())
USRSet.insert(getUSRForDecl(CtorDecl));
+ // Add template constructor decls, they are not in ctors() unfortunately.
+ if (RecordDecl->hasUserDeclaredConstructor())
+ for (const auto *D : RecordDecl->decls())
+ if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
+ if (const auto *Ctor =
+ dyn_cast<CXXConstructorDecl>(FTD->getTemplatedDecl()))
+ USRSet.insert(getUSRForDecl(Ctor));
USRSet.insert(getUSRForDecl(RecordDecl->getDestructor()));
USRSet.insert(getUSRForDecl(RecordDecl));
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -137,6 +137,17 @@
};
)cpp",
+ // Rename template class constructor.
+ R"cpp(
+ class [[F^oo]] {
+ template<typename T>
+ [[Fo^o]]();
+
+ template<typename T>
+ [[F^oo]](T t);
+ };
+ )cpp",
+
// Class in template argument.
R"cpp(
class [[F^oo]] {};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74216.243752.patch
Type: text/x-patch
Size: 2370 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200211/1ca186dc/attachment.bin>
More information about the cfe-commits
mailing list