Skip to content

Commit 4782762

Browse files
committedAug 15, 2017
[index] Update indexing to handle CXXDeductionGuideDecls properly
CXXDeductionGuideDecls can't be referenced so there's no need to output a symbol occurrence for them. Also handle DeducedTemplateSpecializationTypeLocs in the TypeIndexer so we don't miss the symbol occurrences of the corresponding template decls. Patch by Nathan Hawes! Differential Revision: https://reviews.llvm.org/D36641 llvm-svn: 310933
1 parent adcfe5d commit 4782762

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed
 

Diff for: ‎clang/lib/Index/IndexDecl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
267267
TypeNameInfo->getTypeLoc().getLocStart(),
268268
Dtor->getParent(), Dtor->getDeclContext());
269269
}
270+
} else if (const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
271+
IndexCtx.handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),
272+
Guide->getLocation(), Guide,
273+
Guide->getDeclContext());
270274
}
271275
// Template specialization arguments.
272276
if (const ASTTemplateArgumentListInfo *TemplateArgInfo =

Diff for: ‎clang/lib/Index/IndexTypeSourceInfo.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
126126
return true;
127127
}
128128

129-
bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
130-
if (const TemplateSpecializationType *T = TL.getTypePtr()) {
129+
template<typename TypeLocType>
130+
bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
131+
if (const auto *T = TL.getTypePtr()) {
131132
if (IndexCtx.shouldIndexImplicitTemplateInsts()) {
132133
if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
133134
IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
@@ -141,6 +142,14 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
141142
return true;
142143
}
143144

145+
bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
146+
return HandleTemplateSpecializationTypeLoc(TL);
147+
}
148+
149+
bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) {
150+
return HandleTemplateSpecializationTypeLoc(TL);
151+
}
152+
144153
bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
145154
const DependentNameType *DNT = TL.getTypePtr();
146155
const NestedNameSpecifier *NNS = DNT->getQualifier();

Diff for: ‎clang/lib/Index/IndexingContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, AST
231231

232232
/// Whether the given NamedDecl should be skipped because it has no name.
233233
static bool shouldSkipNamelessDecl(const NamedDecl *ND) {
234-
return ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) &&
235-
!isa<ObjCCategoryDecl>(ND);
234+
return (ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) &&
235+
!isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
236236
}
237237

238238
static const Decl *adjustParent(const Decl *Parent) {

Diff for: ‎clang/test/Index/Core/index-source.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,19 @@ void localStructuredBindingAndRef() {
497497

498498
}
499499

500+
template<typename T>
501+
struct Guided { T t; };
502+
// CHECK: [[@LINE-1]]:8 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Def | rel: 0
503+
// CHECK-NEXT: [[@LINE-2]]:19 | field/C++ | t | c:@ST>1#T@Guided@FI@t | <no-cgname> | Def,RelChild | rel: 1
504+
// CHECK-NEXT: RelChild | Guided | c:@ST>1#T@Guided
505+
Guided(double) -> Guided<float>;
506+
// CHECK: [[@LINE-1]]:19 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Ref | rel: 0
507+
// CHECK-NEXT: [[@LINE-2]]:1 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Ref | rel: 0
508+
auto guided = Guided{1.0};
509+
// CHECK: [[@LINE-1]]:6 | variable/C | guided | c:@guided | _guided | Def | rel: 0
510+
// CHECK-NEXT: [[@LINE-2]]:15 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Ref,RelCont | rel: 1
511+
// CHECK-NEXT: RelCont | guided | c:@guided
512+
500513
namespace rd33122110 {
501514

502515
struct Outer {

0 commit comments

Comments
 (0)
Please sign in to comment.