Diagnose the declaration of explicit specializations after an implicit
instantiation has already been required. To do so, keep track of the
point of instantiation for anything that can be instantiated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83890 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 86c5719..638d1cf 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -374,8 +374,7 @@
}
VarDecl *VarDecl::getInstantiatedFromStaticDataMember() {
- if (MemberSpecializationInfo *MSI
- = getASTContext().getInstantiatedFromStaticDataMember(this))
+ if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo())
return cast<VarDecl>(MSI->getInstantiatedFrom());
return 0;
@@ -389,9 +388,12 @@
return TSK_Undeclared;
}
+MemberSpecializationInfo *VarDecl::getMemberSpecializationInfo() {
+ return getASTContext().getInstantiatedFromStaticDataMember(this);
+}
+
void VarDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
- MemberSpecializationInfo *MSI
- = getASTContext().getInstantiatedFromStaticDataMember(this);
+ MemberSpecializationInfo *MSI = getMemberSpecializationInfo();
assert(MSI && "Not an instantiated static data member?");
MSI->setTemplateSpecializationKind(TSK);
}
@@ -703,13 +705,16 @@
}
FunctionDecl *FunctionDecl::getInstantiatedFromMemberFunction() const {
- if (MemberSpecializationInfo *Info
- = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>())
+ if (MemberSpecializationInfo *Info = getMemberSpecializationInfo())
return cast<FunctionDecl>(Info->getInstantiatedFrom());
return 0;
}
+MemberSpecializationInfo *FunctionDecl::getMemberSpecializationInfo() const {
+ return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>();
+}
+
void
FunctionDecl::setInstantiationOfMemberFunction(FunctionDecl *FD,
TemplateSpecializationKind TSK) {
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 64e8000..b9a87ae 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -434,13 +434,16 @@
}
CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const {
- if (MemberSpecializationInfo *MSInfo
- = TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>())
+ if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
return 0;
}
+MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const {
+ return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
+}
+
void
CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD,
TemplateSpecializationKind TSK) {
@@ -456,8 +459,7 @@
= dyn_cast<ClassTemplateSpecializationDecl>(this))
return Spec->getSpecializationKind();
- if (MemberSpecializationInfo *MSInfo
- = TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>())
+ if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
return MSInfo->getTemplateSpecializationKind();
return TSK_Undeclared;
@@ -471,8 +473,7 @@
return;
}
- if (MemberSpecializationInfo *MSInfo
- = TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>()) {
+ if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
MSInfo->setTemplateSpecializationKind(TSK);
return;
}