Skip to content

Commit

Permalink
clang-rename: implement renaming of classes inside static_cast
Browse files Browse the repository at this point in the history
"Derived" in static_cast<Derived&>(...) wasn't renamed, nor in its
pointer equivalent.

Reviewers: klimek

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

llvm-svn: 271933
  • Loading branch information
vmiklos committed Jun 6, 2016
1 parent 82c4478 commit b54a26d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions clang-tools-extra/clang-rename/USRLocFinder.cpp
Expand Up @@ -123,6 +123,23 @@ class USRLocFindingASTVisitor
return true;
}

bool VisitCXXStaticCastExpr(clang::CXXStaticCastExpr *Expr) {
clang::QualType Type = Expr->getType();
// See if this a cast of a pointer.
const RecordDecl* Decl = Type->getPointeeCXXRecordDecl();
if (!Decl) {
// See if this is a cast of a reference.
Decl = Type->getAsCXXRecordDecl();
}

if (Decl && getUSRForDecl(Decl) == USR) {
SourceLocation Location = Expr->getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
LocationsFound.push_back(Location);
}

return true;
}

// Non-visitors:

// \brief Returns a list of unique locations. Duplicate or overlapping
Expand Down
24 changes: 24 additions & 0 deletions clang-tools-extra/test/clang-rename/StaticCastExpr.cpp
@@ -0,0 +1,24 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=150 -new-name=X %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class Base {
};

class Derived : public Base {
public:
int getValue() const {
return 0;
}
};

int main() {
Derived D;
const Base &Reference = D;
const Base *Pointer = &D;

static_cast<const Derived &>(Reference).getValue(); // CHECK: static_cast<const X &>
static_cast<const Derived *>(Pointer)->getValue(); // CHECK: static_cast<const X *>
}

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

0 comments on commit b54a26d

Please sign in to comment.