From: Fangrui Song Date: Sun, 23 Sep 2018 08:23:48 +0000 (+0000) Subject: [Index] Report specialization bases as references when IndexImplicitInstantiation... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=592222551abab9d1dc29a2bce445c8464b9eb1fe;p=clang [Index] Report specialization bases as references when IndexImplicitInstantiation is true Summary: template struct B {}; template struct D : B {}; // `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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342831 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/IndexTypeSourceInfo.cpp b/lib/Index/IndexTypeSourceInfo.cpp index 4b6bfbc67e..8342e93c15 100644 --- a/lib/Index/IndexTypeSourceInfo.cpp +++ b/lib/Index/IndexTypeSourceInfo.cpp @@ -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; } diff --git a/test/Index/index-template-specialization.cpp b/test/Index/index-template-specialization.cpp index d11754113c..d50da0f2d6 100644 --- a/test/Index/index-template-specialization.cpp +++ b/test/Index/index-template-specialization.cpp @@ -9,6 +9,12 @@ void g() { foo.f(0); } +template +struct B {}; + +template +struct D : B {}; + // 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: : kind: c++-class-template | name: B +// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: B