[PATCH] D20150: clang-rename: fix renaming of field with implicit initializers

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 01:14:09 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL269161: clang-rename: fix renaming of field with implicit initializers (authored by vmiklos).

Changed prior to commit:
  http://reviews.llvm.org/D20150?vs=56854&id=56859#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20150

Files:
  clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
  clang-tools-extra/trunk/test/clang-rename/CtorInitializerTest.cpp

Index: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
===================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
@@ -60,6 +60,11 @@
   bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) {
     for (clang::CXXConstructorDecl::init_const_iterator it = ConstructorDecl->init_begin(); it != ConstructorDecl->init_end(); ++it) {
       const clang::CXXCtorInitializer* Initializer = *it;
+      if (Initializer->getSourceOrder() == -1) {
+        // Ignore implicit initializers.
+        continue;
+      }
+
       if (const clang::FieldDecl *FieldDecl = Initializer->getAnyMember()) {
         if (getUSRForDecl(FieldDecl) == USR) {
           // The initializer refers to a field that is to be renamed.
Index: clang-tools-extra/trunk/test/clang-rename/CtorInitializerTest.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-rename/CtorInitializerTest.cpp
+++ clang-tools-extra/trunk/test/clang-rename/CtorInitializerTest.cpp
@@ -0,0 +1,20 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=162 -new-name=hector %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+class A
+{
+};
+
+class Cla
+{
+  A foo; // CHECK: hector;
+public:
+  Cla();
+};
+
+Cla::Cla() // CHECK: Cla::Cla()
+{
+}
+
+// Use grep -FUbo 'foo' <file> to get the correct offset of foo when changing
+// this file.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20150.56859.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160511/226f5b34/attachment.bin>


More information about the cfe-commits mailing list