diff options
-rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 20 | ||||
-rw-r--r-- | clang/test/Index/Core/index-instantiated-source.cpp | 7 |
2 files changed, 21 insertions, 6 deletions
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index b9f991d6ba6..1a341b04c43 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -128,9 +128,8 @@ bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) { 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::shouldIgnoreIfImplicit(const Decl *D) { 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 *adjustTemplateImplicitInstantiation(const Decl *D) { } 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; diff --git a/clang/test/Index/Core/index-instantiated-source.cpp b/clang/test/Index/Core/index-instantiated-source.cpp index a1fe4a340a1..b0c94195a1a 100644 --- a/clang/test/Index/Core/index-instantiated-source.cpp +++ b/clang/test/Index/Core/index-instantiated-source.cpp @@ -28,6 +28,10 @@ public: struct NestedType { // CHECK: [[@LINE-1]]:10 | struct/C++ | NestedType | c:@ST>2#T#T@TemplateClass@S@NestedType | + + T nestedField; +// CHECK: [[@LINE-1]]:7 | field/C++ | nestedField | c:@ST>2#T#T@TemplateClass@S@NestedType@FI@nestedField | + class SubNestedType { // CHECK: [[@LINE-1]]:11 | class/C++ | SubNestedType | c:@ST>2#T#T@TemplateClass@S@NestedType@S@SubNestedType | public: @@ -53,6 +57,9 @@ void canonicalizeInstaniationReferences(TemplateClass<int, float> &object) { // CHECK: [[@LINE-1]]:30 | struct/C | NestedBaseType | c:@ST>1#T@BaseTemplate@S@NestedBaseType | TemplateClass<int, float>::NestedType nestedSubType; // CHECK: [[@LINE-1]]:30 | struct/C++ | NestedType | c:@ST>2#T#T@TemplateClass@S@NestedType | + (void)nestedSubType.nestedField; +// CHECK: [[@LINE-1]]:23 | field/C++ | nestedField | c:@ST>2#T#T@TemplateClass@S@NestedType@FI@nestedField | + typedef TemplateClass<int, float> TT; TT::NestedType::SubNestedType subNestedType(0); // CHECK: [[@LINE-1]]:7 | struct/C++ | NestedType | c:@ST>2#T#T@TemplateClass@S@NestedType | |