[PATCH] D20635: clang-rename: fix renaming heap allocations

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Wed May 25 11:38:25 PDT 2016


vmiklos created this revision.
vmiklos added reviewers: klimek, cfe-commits.

The check failed, 'Cla *C = new Cla();' was renamed 'D *C = new Cla();'.

http://reviews.llvm.org/D20635

Files:
  clang-rename/USRLocFinder.cpp
  test/clang-rename/ConstructExpr.cpp

Index: test/clang-rename/ConstructExpr.cpp
===================================================================
--- /dev/null
+++ 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.
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -112,6 +112,17 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20635.58467.patch
Type: text/x-patch
Size: 1112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160525/7cb1c50e/attachment.bin>


More information about the cfe-commits mailing list