diff options
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 21 | ||||
-rw-r--r-- | clang/test/SemaTemplate/template-decl-fail.cpp | 2 |
2 files changed, 14 insertions, 9 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 6669d40cca0..91050e0a4cf 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -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; diff --git a/clang/test/SemaTemplate/template-decl-fail.cpp b/clang/test/SemaTemplate/template-decl-fail.cpp index 7c04131eba2..ad134cdf225 100644 --- a/clang/test/SemaTemplate/template-decl-fail.cpp +++ b/clang/test/SemaTemplate/template-decl-fail.cpp @@ -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) {} |