]> granicus.if.org Git - clang/commitdiff
[clang-rename] Fix a crash when renaming a class without definition.
authorHaojian Wu <hokein@google.com>
Fri, 4 Oct 2019 14:09:31 +0000 (14:09 +0000)
committerHaojian Wu <hokein@google.com>
Fri, 4 Oct 2019 14:09:31 +0000 (14:09 +0000)
Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68459

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373748 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
test/clang-rename/ForwardClassDecl.cpp [new file with mode: 0644]

index b60616ecc87f25164ee795a063b48fe5ad1f0289..e26248f50c298b801a7bb1600646ba6144af774c 100644 (file)
@@ -102,6 +102,10 @@ public:
 
 private:
   void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) {
+    if (!RecordDecl->getDefinition()) {
+      USRSet.insert(getUSRForDecl(RecordDecl));
+      return;
+    }
     RecordDecl = RecordDecl->getDefinition();
     if (const auto *ClassTemplateSpecDecl =
             dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl))
diff --git a/test/clang-rename/ForwardClassDecl.cpp b/test/clang-rename/ForwardClassDecl.cpp
new file mode 100644 (file)
index 0000000..ef731a1
--- /dev/null
@@ -0,0 +1,4 @@
+class Foo; // CHECK: class Bar;
+Foo *f();  // CHECK: Bar *f();
+
+// RUN: clang-rename -offset=6 -new-name=Bar %s --  | sed 's,//.*,,' | FileCheck %s