r303647 - [index] The references to fields from nested records in template instantiations

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Tue May 23 09:25:07 PDT 2017


Author: arphaman
Date: Tue May 23 11:25:06 2017
New Revision: 303647

URL: http://llvm.org/viewvc/llvm-project?rev=303647&view=rev
Log:
[index] The references to fields from nested records in template instantiations
should refer to the pattern fields in the nested records in the base templates

rdar://32352429

Modified:
    cfe/trunk/lib/Index/IndexingContext.cpp
    cfe/trunk/test/Index/Core/index-instantiated-source.cpp

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=303647&r1=303646&r2=303647&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Tue May 23 11:25:06 2017
@@ -128,9 +128,8 @@ bool IndexingContext::isTemplateImplicit
     if (RD->getInstantiatedFromMemberClass())
       TKind = RD->getTemplateSpecializationKind();
   } else if (isa<FieldDecl>(D)) {
-    if (const auto *Parent =
-            dyn_cast<ClassTemplateSpecializationDecl>(D->getDeclContext()))
-      TKind = Parent->getSpecializationKind();
+    if (const auto *Parent = dyn_cast<Decl>(D->getDeclContext()))
+      return isTemplateImplicitInstantiation(Parent);
   }
   switch (TKind) {
     case TSK_Undeclared:
@@ -158,6 +157,16 @@ bool IndexingContext::shouldIgnoreIfImpl
   return true;
 }
 
+static const CXXRecordDecl *
+getDeclContextForTemplateInstationPattern(const Decl *D) {
+  if (const auto *CTSD =
+          dyn_cast<ClassTemplateSpecializationDecl>(D->getDeclContext()))
+    return CTSD->getTemplateInstantiationPattern();
+  else if (const auto *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext()))
+    return RD->getInstantiatedFromMemberClass();
+  return nullptr;
+}
+
 static const Decl *adjustTemplateImplicitInstantiation(const Decl *D) {
   if (const ClassTemplateSpecializationDecl *
       SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
@@ -169,9 +178,8 @@ static const Decl *adjustTemplateImplici
   } else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
     return RD->getInstantiatedFromMemberClass();
   } else if (const auto *FD = dyn_cast<FieldDecl>(D)) {
-    if (const auto *Parent =
-            dyn_cast<ClassTemplateSpecializationDecl>(D->getDeclContext())) {
-      const CXXRecordDecl *Pattern = Parent->getTemplateInstantiationPattern();
+    if (const CXXRecordDecl *Pattern =
+            getDeclContextForTemplateInstationPattern(FD)) {
       for (const NamedDecl *ND : Pattern->lookup(FD->getDeclName())) {
         if (ND->isImplicit())
           continue;

Modified: cfe/trunk/test/Index/Core/index-instantiated-source.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-instantiated-source.cpp?rev=303647&r1=303646&r2=303647&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-instantiated-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-instantiated-source.cpp Tue May 23 11:25:06 2017
@@ -28,6 +28,10 @@ public:
 
   struct NestedType {
 // CHECK: [[@LINE-1]]:10 | struct/C++ | NestedType | c:@ST>2#T#T at TemplateClass@S at NestedType |
+
+    T nestedField;
+// CHECK: [[@LINE-1]]:7 | field/C++ | nestedField | c:@ST>2#T#T at TemplateClass@S at NestedType@FI at nestedField |
+
     class SubNestedType {
 // CHECK: [[@LINE-1]]:11 | class/C++ | SubNestedType | c:@ST>2#T#T at TemplateClass@S at NestedType@S at SubNestedType |
     public:
@@ -53,6 +57,9 @@ void canonicalizeInstaniationReferences(
 // CHECK: [[@LINE-1]]:30 | struct/C | NestedBaseType | c:@ST>1#T at BaseTemplate@S at NestedBaseType |
   TemplateClass<int, float>::NestedType nestedSubType;
 // CHECK: [[@LINE-1]]:30 | struct/C++ | NestedType | c:@ST>2#T#T at TemplateClass@S at NestedType |
+  (void)nestedSubType.nestedField;
+// CHECK: [[@LINE-1]]:23 | field/C++ | nestedField | c:@ST>2#T#T at TemplateClass@S at NestedType@FI at nestedField |
+
   typedef TemplateClass<int, float> TT;
   TT::NestedType::SubNestedType subNestedType(0);
 // CHECK: [[@LINE-1]]:7 | struct/C++ | NestedType | c:@ST>2#T#T at TemplateClass@S at NestedType |




More information about the cfe-commits mailing list