[Index] Report specialization bases as references when IndexImplicitInstantiation...
authorFangrui Song <maskray@google.com>
Sun, 23 Sep 2018 08:23:48 +0000 (08:23 +0000)
committerFangrui Song <maskray@google.com>
Sun, 23 Sep 2018 08:23:48 +0000 (08:23 +0000)
Summary:
    template <typename T> struct B {};
    template <typename T> struct D : B<T> {}; // `B` was not reported as a reference

This patch fixes this.

Reviewers: akyrtzi, arphaman, devnexen

Reviewed By: devnexen

Subscribers: cfe-commits

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

llvm-svn: 342831

clang/lib/Index/IndexTypeSourceInfo.cpp
clang/test/Index/index-template-specialization.cpp

index 4b6bfbc..8342e93 100644 (file)
@@ -130,14 +130,15 @@ public:
   bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
     if (const auto *T = TL.getTypePtr()) {
       if (IndexCtx.shouldIndexImplicitInstantiation()) {
-        if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
+        if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) {
           IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
                                    Parent, ParentDC, SymbolRoleSet(), Relations);
-      } else {
-        if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl())
-          IndexCtx.handleReference(D, TL.getTemplateNameLoc(),
-                                   Parent, ParentDC, SymbolRoleSet(), Relations);
+          return true;
+        }
       }
+      if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl())
+        IndexCtx.handleReference(D, TL.getTemplateNameLoc(), Parent, ParentDC,
+                                 SymbolRoleSet(), Relations);
     }
     return true;
   }
index d117541..d50da0f 100644 (file)
@@ -9,6 +9,12 @@ void g() {
   foo.f(0);
 }
 
+template <typename T>
+struct B {};
+
+template <typename T>
+struct D : B<T> {};
+
 // FIXME: if c-index-test uses OrigD for symbol info, refererences below should
 // refer to template specialization decls.
 // RUN: env CINDEXTEST_INDEXIMPLICITTEMPLATEINSTANTIATIONS=1 c-index-test -index-file %s | FileCheck %s
@@ -17,3 +23,7 @@ void g() {
 // CHECK-NEXT: [indexDeclaration]: kind: function | name: g
 // CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: Foo | USR: c:@ST>1#T@Foo
 // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: f | USR: c:@ST>1#T@Foo@F@f#t0.0#
+
+// CHECK: [indexDeclaration]: kind: c++-class-template | name: D
+// CHECK-NEXT: <base>: kind: c++-class-template | name: B
+// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: B