return false;
if (auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
assert(CXXDecl->isCompleteDefinition() && "incomplete record definition");
- if (CXXDecl->getTemplateSpecializationKind() != TSK_Undeclared)
- // Make sure the instantiation is actually in a module.
- if (CXXDecl->field_begin() != CXXDecl->field_end())
- return CXXDecl->field_begin()->isFromASTFile();
+ auto TemplateKind = CXXDecl->getTemplateSpecializationKind();
+ if (TemplateKind != TSK_Undeclared) {
+ // This is a template, check the origin of the first member.
+ if (CXXDecl->field_begin() == CXXDecl->field_end())
+ return TemplateKind == TSK_ExplicitInstantiationDeclaration;
+ if (!CXXDecl->field_begin()->isFromASTFile())
+ return false;
+ }
}
-
return true;
}
template <class T> struct FwdDeclTemplateMember<T>::Member { T t; };
TypedefFwdDeclTemplateMember tdfdtm;
+SpecializedBase definedLocally3;
+extern template class WithSpecializedBase<int>;
+WithSpecializedBase<int> definedLocally4;
+
void foo() {
anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
}
// CHECK: !DICompositeType(tag: DW_TAG_class_type,
// CHECK-SAME: name: "Template<float, DebugCXX::traits<float> >",
// CHECK-SAME: scope: ![[NS]],
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
// CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")
-// This type is anchored in the module by an explicit template instantiation.
+// This type is anchored in the module via a function argument,
+// but we don't know this (yet).
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
// CHECK-SAME: scope: ![[NS]],
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: elements:
// CHECK-SAME: identifier: "_ZTSN8DebugCXX1AIJvEEE")
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
// This one isn't.
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTS9Template1IPvE")
// CHECK-SAME: identifier: "_ZTS9Template1IiE")
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")
// CHECK-SAME: elements:
// CHECK-SAME: identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
+// This type is defined locally and forward-declared in the module.
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "SpecializedBase",
+// CHECK-SAME: baseType: ![[SPECIALIZEDBASE:.*]])
+// CHECK: ![[SPECIALIZEDBASE]] =
+// CHECK-SAME: !DICompositeType(tag: DW_TAG_class_type,
+// CHECK-SAME: name: "WithSpecializedBase<float>",
+// CHECK-SAME: elements:
+// CHECK-SAME: identifier: "_ZTS19WithSpecializedBaseIfE")
+
+// This type is explicitly specialized locally.
+// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "WithSpecializedBase<int>",
+// CHECK-SAME: elements:
+// CHECK-SAME: identifier: "_ZTS19WithSpecializedBaseIiE")
// CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
// This type is anchored by a function parameter.
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>"
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTSN8DebugCXX1AIJvEEE")
// This type is anchored by an explicit template instantiation.
// CHECK: !DICompositeType(tag: DW_TAG_class_type,
// CHECK-SAME: name: "Template<int, DebugCXX::traits<int> >"
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
// CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIiEE")
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>"
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")
// CHECK: !DICompositeType(tag: DW_TAG_class_type,
// CHECK-SAME: name: "Template<long, DebugCXX::traits<long> >"
+// CHECK-SAME: elements:
// CHECK-SAME: templateParams:
// CHECK-SAME: identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
// CHECK-SAME: flags: DIFlagFwdDecl
// CHECK-SAME: identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "SpecializedBase",
+// CHECK-SAME: baseType: ![[SPECIALIZEDBASE:.*]])
+// CHECK: ![[SPECIALIZEDBASE]] = !DICompositeType(tag: DW_TAG_class_type,
+// CHECK-SAME: name: "WithSpecializedBase<float>",
+// CHECK-SAME: flags: DIFlagFwdDecl,
+
// CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl"