Index: clang-rename/USRLocFinder.cpp =================================================================== --- clang-rename/USRLocFinder.cpp +++ clang-rename/USRLocFinder.cpp @@ -111,6 +111,11 @@ return true; } + bool VisitCXXMethodDecl(CXXMethodDecl *Decl) { + handleCXXMethodDecl(Decl, Decl->getLocation()); + return true; + } + // Expression visitors: bool VisitDeclRefExpr(const DeclRefExpr *Expr) { @@ -163,6 +168,12 @@ return handleCXXNamedCastExpr(Expr); } + bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *Expr) { + CXXMethodDecl *Decl = Expr->getMethodDecl(); + handleCXXMethodDecl(Decl, Expr->getExprLoc()); + return true; + } + // Non-visitors: // \brief Returns a list of unique locations. Duplicate or overlapping @@ -200,6 +211,21 @@ return true; } + void handleCXXMethodDecl(const CXXMethodDecl* Decl, SourceLocation Location) { + if (getUSRForDecl(Decl) == USR) { + // This member function was requested to be renamed explicitly. + LocationsFound.push_back(Location); + } + else if (Decl->isVirtual()) { + for (auto *OverridenDecl : Decl->overridden_methods()) { + if (getUSRForDecl(OverridenDecl) == USR) { + // This member function overwrites one that is to be renamed. + LocationsFound.push_back(Location); + } + } + } + } + // All the locations of the USR were found. const std::string USR; // Old name that is renamed. Index: test/clang-rename/VirtualFunction.cpp =================================================================== --- /dev/null +++ test/clang-rename/VirtualFunction.cpp @@ -0,0 +1,26 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=163 -new-name=boo %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +class A { +public: + virtual void foo() { } // CHECK: virtual void boo() { } +}; + +class B : public A { +public: + void foo() { } // CHECK: void boo() { } +}; + +int main() { + A a; + a.foo(); // CHECK: a.boo(); + + B b; + b.foo(); // CHECK: b.boo(); + + return 0; +} + +// Use grep -FUbo 'foo' to get the correct offset of foo when changing +// this file.