From: Richard Smith Date: Mon, 1 Apr 2013 21:43:41 +0000 (+0000) Subject: PR15633: Note that we are EnteringContext when parsing the nested name X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=725fe0ede4c5355666a300f4fd7dae9454f35a37;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178502 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticCommonKinds.td b/include/clang/Basic/DiagnosticCommonKinds.td index 14fbe39d09..7ff6ae13b4 100644 --- a/include/clang/Basic/DiagnosticCommonKinds.td +++ b/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/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index c834e195b3..d0bddae1e0 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/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/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 03bffde06e..87b8a2d906 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/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/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 795d97d3ea..5f7399a3d4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/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/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp index a1f911d79d..d01000d22b 100644 --- a/test/SemaCXX/enum-scoped.cpp +++ b/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}} +}