It's okay to reference an enum in a template definition, even though

it's ill-formed to form an enum template. Fixes <rdar://problem/7933063>.

llvm-svn: 102926
This commit is contained in:
Douglas Gregor 2010-05-03 17:48:54 +00:00
parent d18dc2c876
commit cbbf3e3b4a
2 changed files with 14 additions and 9 deletions

View File

@ -1900,15 +1900,6 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
return;
}
// enums cannot be templates.
if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
Diag(Tok, diag::err_enum_template);
// Skip the rest of this declarator, up until the comma or semicolon.
SkipUntil(tok::comma, true);
return;
}
// If an identifier is present, consume and remember it.
IdentifierInfo *Name = 0;
SourceLocation NameLoc;
@ -1932,6 +1923,18 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
TUK = Action::TUK_Declaration;
else
TUK = Action::TUK_Reference;
// enums cannot be templates, although they can be referenced from a
// template.
if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
TUK != Action::TUK_Reference) {
Diag(Tok, diag::err_enum_template);
// Skip the rest of this declarator, up until the comma or semicolon.
SkipUntil(tok::comma, true);
return;
}
bool Owned = false;
bool IsDependent = false;
SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc;

View File

@ -6,3 +6,5 @@ template<typename T>
enum t0 { A = T::x }; // expected-error{{enumeration cannot be a template}} \
// expected-warning{{declaration does not declare anything}}
enum e0 {};
template<int x> enum e0 f0(int a=x) {}