]> granicus.if.org Git - clang/commitdiff
[index] Update indexing to handle CXXDeductionGuideDecls properly
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 15 Aug 2017 17:20:37 +0000 (17:20 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 15 Aug 2017 17:20:37 +0000 (17:20 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310933 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Index/IndexDecl.cpp
lib/Index/IndexTypeSourceInfo.cpp
lib/Index/IndexingContext.cpp
test/Index/Core/index-source.cpp

index c5230c0f9acf89e4b3e060ed9a40cf7447589f57..fe6beef6705b5a5d5409adc0667ec2b06adeda2e 100644 (file)
@@ -267,6 +267,10 @@ public:
                                  TypeNameInfo->getTypeLoc().getLocStart(),
                                  Dtor->getParent(), Dtor->getDeclContext());
       }
+    } else if (const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
+      IndexCtx.handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),
+                               Guide->getLocation(), Guide,
+                               Guide->getDeclContext());
     }
     // Template specialization arguments.
     if (const ASTTemplateArgumentListInfo *TemplateArgInfo =
index ae27ebe6ea4c0831883dd9ff9bc56dadaafddb52..c8ff3d72d4be1362c4a56bb2bc772f923b03f5c6 100644 (file)
@@ -126,8 +126,9 @@ public:
     return true;
   }
 
-  bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
-    if (const TemplateSpecializationType *T = TL.getTypePtr()) {
+  template<typename TypeLocType>
+  bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
+    if (const auto *T = TL.getTypePtr()) {
       if (IndexCtx.shouldIndexImplicitTemplateInsts()) {
         if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
           IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
@@ -141,6 +142,14 @@ public:
     return true;
   }
 
+  bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
+    return HandleTemplateSpecializationTypeLoc(TL);
+  }
+
+  bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) {
+    return HandleTemplateSpecializationTypeLoc(TL);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
     const DependentNameType *DNT = TL.getTypePtr();
     const NestedNameSpecifier *NNS = DNT->getQualifier();
index addee691e80463ce4623e73daa0f4f1924eec6c1..de9fe39df0310ca59e1ed9278b32684610a9bbee 100644 (file)
@@ -231,8 +231,8 @@ static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, AST
 
 /// Whether the given NamedDecl should be skipped because it has no name.
 static bool shouldSkipNamelessDecl(const NamedDecl *ND) {
-  return ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) &&
-         !isa<ObjCCategoryDecl>(ND);
+  return (ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) &&
+          !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND);
 }
 
 static const Decl *adjustParent(const Decl *Parent) {
index 4864d6cf0150ad78df1c37990ff10654d122b8ef..f9c88d5ea68e60944997d41d767edc9821924744 100644 (file)
@@ -497,6 +497,19 @@ void localStructuredBindingAndRef() {
 
 }
 
+template<typename T>
+struct Guided { T t; };
+// CHECK: [[@LINE-1]]:8 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Def | rel: 0
+// CHECK-NEXT: [[@LINE-2]]:19 | field/C++ | t | c:@ST>1#T@Guided@FI@t | <no-cgname> | Def,RelChild | rel: 1
+// CHECK-NEXT: RelChild | Guided | c:@ST>1#T@Guided
+Guided(double) -> Guided<float>;
+// CHECK: [[@LINE-1]]:19 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Ref | rel: 0
+// CHECK-NEXT: [[@LINE-2]]:1 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Ref | rel: 0
+auto guided = Guided{1.0};
+// CHECK: [[@LINE-1]]:6 | variable/C | guided | c:@guided | _guided | Def | rel: 0
+// CHECK-NEXT: [[@LINE-2]]:15 | struct(Gen)/C++ | Guided | c:@ST>1#T@Guided | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | guided | c:@guided
+
 namespace rd33122110 {
 
 struct Outer {