summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@vmiklos.hu>2016-05-07 14:32:59 +0000
committerMiklos Vajna <vmiklos@vmiklos.hu>2016-05-07 14:32:59 +0000
commit65f088f5280dd1b41224263304fb824d981b722a (patch)
treed5294e0157e7ea58c871a8bd06e7231342269934
parent3bf8061f1a69f034442df9ec27b26cfe03693139 (diff)
downloadbcm5719-llvm-65f088f5280dd1b41224263304fb824d981b722a.tar.gz
bcm5719-llvm-65f088f5280dd1b41224263304fb824d981b722a.zip
clang-rename: when renaming a field, rename initializers of that field as well
Summary: The second check failed, the initializer wasn't renamed. Reviewers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D19957 llvm-svn: 268857
-rw-r--r--clang-tools-extra/clang-rename/USRLocFinder.cpp13
-rw-r--r--clang-tools-extra/test/clang-rename/FieldTest.cpp17
2 files changed, 30 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-rename/USRLocFinder.cpp b/clang-tools-extra/clang-rename/USRLocFinder.cpp
index c7bf1068fa7..acb47bb41f6 100644
--- a/clang-tools-extra/clang-rename/USRLocFinder.cpp
+++ b/clang-tools-extra/clang-rename/USRLocFinder.cpp
@@ -57,6 +57,19 @@ public:
return true;
}
+ bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) {
+ for (clang::CXXConstructorDecl::init_const_iterator it = ConstructorDecl->init_begin(); it != ConstructorDecl->init_end(); ++it) {
+ const clang::CXXCtorInitializer* Initializer = *it;
+ if (const clang::FieldDecl *FieldDecl = Initializer->getAnyMember()) {
+ if (getUSRForDecl(FieldDecl) == USR) {
+ // The initializer refers to a field that is to be renamed.
+ LocationsFound.push_back(Initializer->getSourceLocation());
+ }
+ }
+ }
+ return true;
+ }
+
// Expression visitors:
bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
diff --git a/clang-tools-extra/test/clang-rename/FieldTest.cpp b/clang-tools-extra/test/clang-rename/FieldTest.cpp
new file mode 100644
index 00000000000..6077841ba04
--- /dev/null
+++ b/clang-tools-extra/test/clang-rename/FieldTest.cpp
@@ -0,0 +1,17 @@
+class Cla
+{
+ int foo; // CHECK: hector;
+public:
+ Cla();
+};
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=18 -new-name=hector %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+
+Cla::Cla()
+ : foo(0) // CHECK: hector(0)
+{
+}
+
+// Use grep -FUbo 'foo' <file> to get the correct offset of foo when changing
+// this file.
OpenPOWER on IntegriCloud