[clang-tools-extra] r271572 - clang-rename: fix renaming heap allocations
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 2 13:00:22 PDT 2016
Author: vmiklos
Date: Thu Jun 2 15:00:22 2016
New Revision: 271572
URL: http://llvm.org/viewvc/llvm-project?rev=271572&view=rev
Log:
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
Added:
clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp
Modified:
clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=271572&r1=271571&r2=271572&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Thu Jun 2 15:00:22 2016
@@ -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
Added: clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp?rev=271572&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-rename/ConstructExpr.cpp Thu Jun 2 15:00:22 2016
@@ -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.
More information about the cfe-commits
mailing list