From 4999d9b0135878f24eae78f33142b4929274dd54 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 10 Mar 2011 10:21:00 -0500 Subject: re PR c++/47198 ([C++0x] ICE: tree check: expected var_decl or function_decl, have template_decl in check_bases_and_members, at cp/class.c:4654 on invalid code) PR c++/47198 * parser.c (cp_parser_single_declaration): Just return if cp_parser_parse_and_diagnose_invalid_type_name complained. From-SVN: r170847 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 23 ++++++++++++++++------- gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/g++.dg/cpp0x/syntax-err1.C | 8 ++++++++ gcc/testsuite/g++.dg/parse/error36.C | 1 - gcc/testsuite/g++.old-deja/g++.pt/ctor2.C | 2 +- gcc/testsuite/g++.old-deja/g++.pt/typename3.C | 2 +- gcc/testsuite/g++.old-deja/g++.pt/typename4.C | 2 +- gcc/testsuite/g++.old-deja/g++.pt/typename6.C | 2 +- 9 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/syntax-err1.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 789b2cf..a3a5bf7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-03-10 Jason Merrill + + PR c++/47198 + * parser.c (cp_parser_single_declaration): Just return if + cp_parser_parse_and_diagnose_invalid_type_name complained. + 2011-03-09 Jason Merrill PR c++/44629 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 510fcb1..7e9b286 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -20102,8 +20102,15 @@ cp_parser_single_declaration (cp_parser* parser, } /* Complain about missing 'typename' or other invalid type names. */ - if (!decl_specifiers.any_type_specifiers_p) - cp_parser_parse_and_diagnose_invalid_type_name (parser); + if (!decl_specifiers.any_type_specifiers_p + && cp_parser_parse_and_diagnose_invalid_type_name (parser)) + { + /* cp_parser_parse_and_diagnose_invalid_type_name calls + cp_parser_skip_to_end_of_block_or_statement, so don't try to parse + the rest of this declaration. */ + decl = error_mark_node; + goto out; + } /* If it's not a template class, try for a template function. If the next token is a `;', then this declaration does not declare @@ -20137,6 +20144,13 @@ cp_parser_single_declaration (cp_parser* parser, } } + /* Look for a trailing `;' after the declaration. */ + if (!function_definition_p + && (decl == error_mark_node + || !cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON))) + cp_parser_skip_to_end_of_block_or_statement (parser); + + out: pop_deferring_access_checks (); /* Clear any current qualification; whatever comes next is the start @@ -20144,11 +20158,6 @@ cp_parser_single_declaration (cp_parser* parser, parser->scope = NULL_TREE; parser->qualifying_scope = NULL_TREE; parser->object_scope = NULL_TREE; - /* Look for a trailing `;' after the declaration. */ - if (!function_definition_p - && (decl == error_mark_node - || !cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON))) - cp_parser_skip_to_end_of_block_or_statement (parser); return decl; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c30b08..9739ac8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2011-03-10 Jason Merrill + + * g++.dg/cpp0x/syntax-err1.C: New. + * g++.dg/parse/error36.C: Adjust expected errors. + * g++.old-deja/g++.pt/ctor2.C: Likewise. + * g++.old-deja/g++.pt/typename3.C: Likewise. + * g++.old-deja/g++.pt/typename4.C: Likewise. + * g++.old-deja/g++.pt/typename6.C: Likewise. + 2011-03-09 Jason Merrill * g++.dg/template/nontype22.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/syntax-err1.C b/gcc/testsuite/g++.dg/cpp0x/syntax-err1.C new file mode 100644 index 0000000..ce1c9ee --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/syntax-err1.C @@ -0,0 +1,8 @@ +// PR c++/47198 +// { dg-options -std=c++0x } + +struct S +{ + template < int > sometype foo (); // { dg-error "sometype. does not name a type" } + S () = default; +}; diff --git a/gcc/testsuite/g++.dg/parse/error36.C b/gcc/testsuite/g++.dg/parse/error36.C index 0d7f8cf..8fcaa2f 100644 --- a/gcc/testsuite/g++.dg/parse/error36.C +++ b/gcc/testsuite/g++.dg/parse/error36.C @@ -30,4 +30,3 @@ void g(const A::type &t); // { dg-error "typename" } // PR c++/18451 template A::B A::b; // { dg-error "typename" } -// { dg-error "expected" "" { target *-*-* } 32 } diff --git a/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C b/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C index eb8f312..a8be91d 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/ctor2.C @@ -10,4 +10,4 @@ struct A { template A::A() // { dg-error "constructor|qualified name" } { -} // { dg-error "end of input" } +} diff --git a/gcc/testsuite/g++.old-deja/g++.pt/typename3.C b/gcc/testsuite/g++.old-deja/g++.pt/typename3.C index 0708f1f..ad026a7 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/typename3.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/typename3.C @@ -18,4 +18,4 @@ struct B : public A template B::A_Type B::Func() { // { dg-error "typename" } implicit typename -} // { dg-error "expected" } +} diff --git a/gcc/testsuite/g++.old-deja/g++.pt/typename4.C b/gcc/testsuite/g++.old-deja/g++.pt/typename4.C index 7238470..47fb250 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/typename4.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/typename4.C @@ -23,4 +23,4 @@ struct C : public B template C::A_Type C::Func() { // { dg-error "typename" } implicit typename -} // { dg-error "expected" } +} diff --git a/gcc/testsuite/g++.old-deja/g++.pt/typename6.C b/gcc/testsuite/g++.old-deja/g++.pt/typename6.C index 0a5f018..7347812 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/typename6.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/typename6.C @@ -17,4 +17,4 @@ struct B : public A template A::A_Type B::Func() // { dg-error "typename" } function { -} // { dg-error "expected" } +} -- cgit v1.1