Author: vmiklos Date: Sat May 7 09:32:59 2016 New Revision: 268857 URL: http://llvm.org/viewvc/llvm-project?rev=268857&view=rev Log: 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 Added: clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=268857&r1=268856&r2=268857&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original) +++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Sat May 7 09:32:59 2016 @@ -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) { Added: clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp?rev=268857&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp (added) +++ clang-tools-extra/trunk/test/clang-rename/FieldTest.cpp Sat May 7 09:32:59 2016 @@ -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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits