// determine whether we have a template or a template specialization.
bool isExplicitSpecialization = false;
unsigned NumMatchedTemplateParamLists = TemplateParamLists.size();
+ bool Invalid = false;
if (TemplateParameterList *TemplateParams
= MatchTemplateParametersToScopeSpecifier(
D.getDeclSpec().getSourceRange().getBegin(),
(TemplateParameterList**)TemplateParamLists.get(),
TemplateParamLists.size(),
/*never a friend*/ false,
- isExplicitSpecialization)) {
+ isExplicitSpecialization,
+ Invalid)) {
// All but one template parameter lists have been matching.
--NumMatchedTemplateParamLists;
VarDecl *NewVD = VarDecl::Create(Context, DC, D.getIdentifierLoc(),
II, R, TInfo, SC, SCAsWritten);
- if (D.isInvalidType())
+ if (D.isInvalidType() || Invalid)
NewVD->setInvalidDecl();
SetNestedNameSpecifier(NewVD, D);
bool isExplicitSpecialization = false;
bool isFunctionTemplateSpecialization = false;
unsigned NumMatchedTemplateParamLists = TemplateParamLists.size();
+ bool Invalid = false;
if (TemplateParameterList *TemplateParams
= MatchTemplateParametersToScopeSpecifier(
D.getDeclSpec().getSourceRange().getBegin(),
(TemplateParameterList**)TemplateParamLists.get(),
TemplateParamLists.size(),
isFriend,
- isExplicitSpecialization)) {
+ isExplicitSpecialization,
+ Invalid)) {
// All but one template parameter lists have been matching.
--NumMatchedTemplateParamLists;
(TemplateParameterList**)TemplateParamLists.release());
}
+ if (Invalid) {
+ NewFD->setInvalidDecl();
+ if (FunctionTemplate)
+ FunctionTemplate->setInvalidDecl();
+ }
+
// C++ [dcl.fct.spec]p5:
// The virtual specifier shall only be used in declarations of
// nonstatic class member functions that appear within a
// FIXME: Check explicit specializations more carefully.
bool isExplicitSpecialization = false;
unsigned NumMatchedTemplateParamLists = TemplateParameterLists.size();
+ bool Invalid = false;
if (TUK != TUK_Reference) {
if (TemplateParameterList *TemplateParams
= MatchTemplateParametersToScopeSpecifier(KWLoc, SS,
(TemplateParameterList**)TemplateParameterLists.get(),
TemplateParameterLists.size(),
TUK == TUK_Friend,
- isExplicitSpecialization)) {
+ isExplicitSpecialization,
+ Invalid)) {
// All but one template parameter lists have been matching.
--NumMatchedTemplateParamLists;
if (TemplateParams->size() > 0) {
// This is a declaration or definition of a class template (which may
// be a member of another template).
+ if (Invalid)
+ return DeclPtrTy();
+
OwnedDecl = false;
DeclResult Result = CheckClassTemplate(S, TagSpec, TUK, KWLoc,
SS, Name, NameLoc, Attr,
DeclContext *SearchDC = CurContext;
DeclContext *DC = CurContext;
bool isStdBadAlloc = false;
- bool Invalid = false;
RedeclarationKind Redecl = ForRedeclaration;
if (TUK == TUK_Friend || TUK == TUK_Reference)
TemplateParameterList **ParamLists,
unsigned NumParamLists,
bool IsFriend,
- bool &IsExplicitSpecialization) {
+ bool &IsExplicitSpecialization,
+ bool &Invalid) {
IsExplicitSpecialization = false;
// Find the template-ids that occur within the nested-name-specifier. These
diag::err_template_spec_needs_template_parameters)
<< TemplateId
<< SS.getRange();
+ Invalid = true;
} else {
Diag(SS.getRange().getBegin(), diag::err_template_spec_needs_header)
<< SS.getRange()
<< ExplicitSpecializationsInSpecifier.back();
ExplicitSpecializationsInSpecifier.pop_back();
}
-
+
+ // We have a template parameter list with no corresponding scope, which
+ // means that the resulting template declaration can't be instantiated
+ // properly (we'll end up with dependent nodes when we shouldn't).
+ if (!isExplicitSpecHeader)
+ Invalid = true;
+
++Idx;
}
}
// template.
// FIXME: We probably shouldn't complain about these headers for
// friend declarations.
+ bool Invalid = false;
TemplateParameterList *TemplateParams
= MatchTemplateParametersToScopeSpecifier(TemplateNameLoc, SS,
(TemplateParameterList**)TemplateParameterLists.get(),
TemplateParameterLists.size(),
TUK == TUK_Friend,
- isExplicitSpecialization);
+ isExplicitSpecialization,
+ Invalid);
+ if (Invalid)
+ return true;
+
unsigned NumMatchedTemplateParamLists = TemplateParameterLists.size();
if (TemplateParams)
--NumMatchedTemplateParamLists;
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only %s 2>&1| FileCheck %s
+
+// PR7511
+
+// Note that the error count below doesn't matter. We just want to
+// make sure that the parser doesn't crash.
+// CHECK: 16 errors
+template<a>
+struct int_;
+
+template<a>
+template<int,typename T1,typename>
+struct ac
+{
+ typedef T1 ae
+};
+
+template<class>struct aaa
+{
+ typedef ac<1,int,int>::ae ae
+};
+
+template<class>
+struct state_machine
+{
+ typedef aaa<int>::ae aaa;
+ int start()
+ {
+ ant(0);
+ }
+
+ template<class>
+ struct region_processing_helper
+ {
+ template<class,int=0>
+ struct In;
+
+ template<int my>
+ struct In<a::int_<aaa::a>,my>;
+
+ template<class Event>
+ int process(Event)
+ {
+ In<a::int_<0> > a;
+ }
+ }
+ template<class Event>
+ int ant(Event)
+ {
+ region_processing_helper<int>* helper;
+ helper->process(0)
+ }
+};
+
+int a()
+{
+ state_machine<int> p;
+ p.ant(0);
+}