From: Ilya Biryukov Date: Thu, 23 May 2019 16:48:47 +0000 (+0000) Subject: [Index] Fix reported references in presence of template type aliases X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51db2e5c4b635698f0ec7aa9fd578e9d4510382d;p=clang [Index] Fix reported references in presence of template type aliases Summary: See the added test for an example. Reviewers: kadircet Reviewed By: kadircet Subscribers: jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62303 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361511 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/IndexTypeSourceInfo.cpp b/lib/Index/IndexTypeSourceInfo.cpp index 9f9740b607..959d5f1197 100644 --- a/lib/Index/IndexTypeSourceInfo.cpp +++ b/lib/Index/IndexTypeSourceInfo.cpp @@ -133,29 +133,41 @@ public: return true; } - template - bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) { - if (const auto *T = TL.getTypePtr()) { - if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) { - if (!RD->isImplicit() || IndexCtx.shouldIndexImplicitInstantiation()) { - IndexCtx.handleReference(RD, TL.getTemplateNameLoc(), Parent, - ParentDC, SymbolRoleSet(), Relations); - return true; - } - } - if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl()) - IndexCtx.handleReference(D, TL.getTemplateNameLoc(), Parent, ParentDC, - SymbolRoleSet(), Relations); + void HandleTemplateSpecializationTypeLoc(TemplateName TemplName, + SourceLocation TemplNameLoc, + CXXRecordDecl *ResolvedClass, + bool IsTypeAlias) { + // In presence of type aliases, the resolved class was never written in + // the code so don't report it. + if (!IsTypeAlias && ResolvedClass && + (!ResolvedClass->isImplicit() || + IndexCtx.shouldIndexImplicitInstantiation())) { + IndexCtx.handleReference(ResolvedClass, TemplNameLoc, Parent, ParentDC, + SymbolRoleSet(), Relations); + } else if (const TemplateDecl *D = TemplName.getAsTemplateDecl()) { + IndexCtx.handleReference(D, TemplNameLoc, Parent, ParentDC, + SymbolRoleSet(), Relations); } - return true; } bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { - return HandleTemplateSpecializationTypeLoc(TL); + auto *T = TL.getTypePtr(); + if (!T) + return true; + HandleTemplateSpecializationTypeLoc( + T->getTemplateName(), TL.getTemplateNameLoc(), T->getAsCXXRecordDecl(), + T->isTypeAlias()); + return true; } bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) { - return HandleTemplateSpecializationTypeLoc(TL); + auto *T = TL.getTypePtr(); + if (!T) + return true; + HandleTemplateSpecializationTypeLoc( + T->getTemplateName(), TL.getTemplateNameLoc(), T->getAsCXXRecordDecl(), + /*IsTypeAlias=*/false); + return true; } bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {