r342831 - [Index] Report specialization bases as references when IndexImplicitInstantiation is true

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 23 01:23:48 PDT 2018


Author: maskray
Date: Sun Sep 23 01:23:48 2018
New Revision: 342831

URL: http://llvm.org/viewvc/llvm-project?rev=342831&view=rev
Log:
[Index] Report specialization bases as references when IndexImplicitInstantiation is true

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

Modified:
    cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
    cfe/trunk/test/Index/index-template-specialization.cpp

Modified: cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp?rev=342831&r1=342830&r2=342831&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp Sun Sep 23 01:23:48 2018
@@ -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;
   }

Modified: cfe/trunk/test/Index/index-template-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-template-specialization.cpp?rev=342831&r1=342830&r2=342831&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-template-specialization.cpp (original)
+++ cfe/trunk/test/Index/index-template-specialization.cpp Sun Sep 23 01:23:48 2018
@@ -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 at Foo
 // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: f | USR: c:@ST>1#T at Foo@F at 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




More information about the cfe-commits mailing list