diff options
author | Miklos Vajna <vmiklos@vmiklos.hu> | 2016-06-02 20:00:22 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@vmiklos.hu> | 2016-06-02 20:00:22 +0000 |
commit | 617409f0c0a990d2d4b62f1a3e02ca26bc41d67a (patch) | |
tree | 950acc4de289227df726f7c2bd5307a219e1f1f7 | |
parent | d1097a38e2b754a98bd60a9581316f0ea9eae6bc (diff) | |
download | bcm5719-llvm-617409f0c0a990d2d4b62f1a3e02ca26bc41d67a.tar.gz bcm5719-llvm-617409f0c0a990d2d4b62f1a3e02ca26bc41d67a.zip |
clang-rename: fix renaming heap allocations
The check failed, 'Cla *C = new Cla();' was renamed to 'D *C = new Cla();'.
Reviewers: klimek
Differential Revision: http://reviews.llvm.org/D20635
llvm-svn: 271572
-rw-r--r-- | clang-tools-extra/clang-rename/USRLocFinder.cpp | 11 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-rename/ConstructExpr.cpp | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-rename/USRLocFinder.cpp b/clang-tools-extra/clang-rename/USRLocFinder.cpp index 43e9524541b..caf4f149009 100644 --- a/clang-tools-extra/clang-rename/USRLocFinder.cpp +++ b/clang-tools-extra/clang-rename/USRLocFinder.cpp @@ -112,6 +112,17 @@ public: return true; } + bool VisitCXXConstructExpr(const CXXConstructExpr *Expr) { + CXXConstructorDecl *Decl = Expr->getConstructor(); + + if (getUSRForDecl(Decl) == USR) { + // This takes care of 'new <name>' expressions. + LocationsFound.push_back(Expr->getLocation()); + } + + return true; + } + // Non-visitors: // \brief Returns a list of unique locations. Duplicate or overlapping diff --git a/clang-tools-extra/test/clang-rename/ConstructExpr.cpp b/clang-tools-extra/test/clang-rename/ConstructExpr.cpp new file mode 100644 index 00000000000..468378aebee --- /dev/null +++ b/clang-tools-extra/test/clang-rename/ConstructExpr.cpp @@ -0,0 +1,14 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=133 -new-name=D %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s +class Cla +{ +}; + +int main() +{ + Cla *C = new Cla(); // CHECK: D *C = new D(); +} + +// Use grep -FUbo 'Cla' <file> to get the correct offset of foo when changing +// this file. |