From 617409f0c0a990d2d4b62f1a3e02ca26bc41d67a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 2 Jun 2016 20:00:22 +0000 Subject: [PATCH] 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 --- clang-tools-extra/clang-rename/USRLocFinder.cpp | 11 +++++++++++ .../test/clang-rename/ConstructExpr.cpp | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 clang-tools-extra/test/clang-rename/ConstructExpr.cpp diff --git a/clang-tools-extra/clang-rename/USRLocFinder.cpp b/clang-tools-extra/clang-rename/USRLocFinder.cpp index 43e9524541b1..caf4f1490097 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 ' 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 000000000000..468378aebee3 --- /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' to get the correct offset of foo when changing +// this file.