From 1d4b2e16a2bc20356e1c79e3115217a80c6104af Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 1 Apr 2013 21:43:41 +0000 Subject: [PATCH] PR15633: Note that we are EnteringContext when parsing the nested name specifier for an enumeration. Also fix a crash-on-invalid if a non-dependent name specifier is used to declare an enum template. llvm-svn: 178502 --- clang/include/clang/Basic/DiagnosticCommonKinds.td | 1 + clang/include/clang/Basic/DiagnosticParseKinds.td | 1 - clang/lib/Parse/ParseDecl.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 5 +++++ clang/test/SemaCXX/enum-scoped.cpp | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index 14fbe39d0920..7ff6ae13b4ef 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -77,6 +77,7 @@ def note_decl_hiding_tag_type : Note< "%1 %0 is hidden by a non-type declaration of %0 here">; def err_attribute_not_type_attr : Error< "%0 attribute cannot be applied to types">; +def err_enum_template : Error<"enumeration cannot be a template">; // Sema && Lex def ext_c99_longlong : Extension< diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index c834e195b3a9..d0bddae1e096 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -556,7 +556,6 @@ def err_explicit_instantiation_with_definition : Error< "explicit template instantiation cannot have a definition; if this " "definition is meant to be an explicit specialization, add '<>' after the " "'template' keyword">; -def err_enum_template : Error<"enumeration cannot be a template">; def err_explicit_instantiation_enum : Error< "enumerations cannot be explicitly instantiated">; def err_expected_template_parameter : Error<"expected template parameter">; diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 03bffde06ea7..87b8a2d906c7 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3262,7 +3262,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, ColonProtectionRAIIObject X(*this, AllowFixedUnderlyingType); if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), - /*EnteringContext=*/false)) + /*EnteringContext=*/true)) return; if (SS.isSet() && Tok.isNot(tok::identifier)) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 795d97d3eaf5..5f7399a3d4c9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9387,6 +9387,11 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, TUK == TUK_Friend, isExplicitSpecialization, Invalid)) { + if (Kind == TTK_Enum) { + Diag(KWLoc, diag::err_enum_template); + return 0; + } + if (TemplateParams->size() > 0) { // This is a declaration or definition of a class template (which may // be a member of another template). diff --git a/clang/test/SemaCXX/enum-scoped.cpp b/clang/test/SemaCXX/enum-scoped.cpp index a1f911d79d39..d01000d22bb4 100644 --- a/clang/test/SemaCXX/enum-scoped.cpp +++ b/clang/test/SemaCXX/enum-scoped.cpp @@ -252,3 +252,17 @@ namespace pr13128 { enum class E { C }; }; } + +namespace PR15633 { + template struct A { + struct B { + enum class E : T; + enum class E2 : T; + }; + }; + template enum class A::B::E { e }; + template class A; + + struct B { enum class E; }; + template enum class B::E { e }; // expected-error {{enumeration cannot be a template}} +}