Skip to content

Commit

Permalink
clang-rename: fix renaming of field with implicit initializers
Browse files Browse the repository at this point in the history
The last check failed as Cla::Cla() was rewritten to Cla::hector().

Reviewers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D20150

llvm-svn: 269161
  • Loading branch information
vmiklos committed May 11, 2016
1 parent 7e61e15 commit 6477682
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang-tools-extra/clang-rename/USRLocFinder.cpp
Expand Up @@ -60,6 +60,11 @@ class USRLocFindingASTVisitor
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 (Initializer->getSourceOrder() == -1) {
// Ignore implicit initializers.
continue;
}

if (const clang::FieldDecl *FieldDecl = Initializer->getAnyMember()) {
if (getUSRForDecl(FieldDecl) == USR) {
// The initializer refers to a field that is to be renamed.
Expand Down
20 changes: 20 additions & 0 deletions clang-tools-extra/test/clang-rename/CtorInitializerTest.cpp
@@ -0,0 +1,20 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=162 -new-name=hector %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class A
{
};

class Cla
{
A foo; // CHECK: hector;
public:
Cla();
};

Cla::Cla() // CHECK: Cla::Cla()
{
}

// Use grep -FUbo 'foo' <file> to get the correct offset of foo when changing
// this file.

0 comments on commit 6477682

Please sign in to comment.