From: Jason Merrill Date: Tue, 22 Dec 2015 21:46:44 +0000 (-0500) Subject: re PR c++/67257 (Internal compiler error in retrieve_specialization) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dfc9c481360183f1b2c4914b66c4303babc04df1;p=gcc.git re PR c++/67257 (Internal compiler error in retrieve_specialization) PR c++/67257 * parser.c (cp_parser_single_declaration): Reject a class template that also declares a variable. From-SVN: r231913 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dbc7b3e8007..c081160f316 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-12-22 Jason Merrill + PR c++/67257 + * parser.c (cp_parser_single_declaration): Reject a class template + that also declares a variable. + PR c++/67339 * parser.c (cp_parser_elaborated_type_specifier): Use CLASS_TYPE_P rather than check for RECORD_TYPE. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 262bfb28805..842dded1fca 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -25642,7 +25642,8 @@ cp_parser_single_declaration (cp_parser* parser, /* Check for the declaration of a template class. */ if (declares_class_or_enum) { - if (cp_parser_declares_only_class_p (parser)) + if (cp_parser_declares_only_class_p (parser) + || (declares_class_or_enum & 2)) { // If this is a declaration, but not a definition, associate // any constraints with the type declaration. Constraints @@ -25673,6 +25674,19 @@ cp_parser_single_declaration (cp_parser* parser, /* Perform access checks for template parameters. */ cp_parser_perform_template_parameter_access_checks (checks); + + /* Give a helpful diagnostic for + template struct A { } a; + if we aren't already recovering from an error. */ + if (!cp_parser_declares_only_class_p (parser) + && !seen_error ()) + { + error_at (cp_lexer_peek_token (parser->lexer)->location, + "a class template declaration must not declare " + "anything else"); + cp_parser_skip_to_end_of_block_or_statement (parser); + goto out; + } } } diff --git a/gcc/testsuite/g++.dg/cpp0x/pr51226.C b/gcc/testsuite/g++.dg/cpp0x/pr51226.C index 7e52e93e219..89200ee3d27 100644 --- a/gcc/testsuite/g++.dg/cpp0x/pr51226.C +++ b/gcc/testsuite/g++.dg/cpp0x/pr51226.C @@ -6,4 +6,7 @@ template struct A // { dg-message "provided" } enum E : int; }; -template<> enum A<>::E : int {} // { dg-error "wrong number|expected" } +template<> enum A<>::E : int {} // { dg-error "wrong number" } + +// { dg-prune-output "expected" } +// { dg-prune-output "specialization" } diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn28.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn28.C new file mode 100644 index 00000000000..fb3659bff8c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn28.C @@ -0,0 +1,11 @@ +// PR c++/67257 +// { dg-do compile { target c++14 } } + +template struct plus; +template struct A { + template auto operator()(T); +} foldl; // { dg-error "" } +void foo() { foldl>(0); } + +// { dg-prune-output "not declared" } +// { dg-prune-output "expected" }