Message ID | 1393969569-5509-1-git-send-email-adam@jessamine.co.uk |
---|---|
State | New |
Headers | show |
On 03/04/2014 04:46 PM, Adam Butcher wrote: > PR c++/60393 > * parser.c (cp_parser_parameter_declaration_clause): Move generic > function template unwinding on error into a move general location, ... > (cp_parser_error): ... here. Hmm, I'm uncomfortable with this change; not all errors lead to unwinding the whole declaration context. Typically they just mean we're changing from one tentative parse to another. If for instance you had a function with one generic parameter and one with a type like A<42>, we would try to parse 42 as a type and hit cp_parser_error before parsing it as an expression. Jason
On 2014-03-07 17:29, Jason Merrill wrote: > On 03/04/2014 04:46 PM, Adam Butcher wrote: >> PR c++/60393 >> * parser.c (cp_parser_parameter_declaration_clause): Move generic >> function template unwinding on error into a move general location, >> ... >> (cp_parser_error): ... here. > > Hmm, I'm uncomfortable with this change; not all errors lead to > unwinding the whole declaration context. Typically they just mean > we're changing from one tentative parse to another. If for instance > you had a function with one generic parameter and one with a type > like > A<42>, we would try to parse 42 as a type and hit cp_parser_error > before parsing it as an expression. > Ah right. I did wonder about tentative parsing. What about in cp_parser_skip_to_end_of_statement? Alternative seems to be that we explicitly handle each case.
On 03/07/2014 02:10 PM, Adam Butcher wrote: > Ah right. I did wonder about tentative parsing. What about in > cp_parser_skip_to_end_of_statement? That sounds OK. Jason
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8c78262..7feae3d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2524,6 +2524,10 @@ cp_parser_error (cp_parser* parser, const char* gmsgid) of the token we just peeked at. */ cp_lexer_set_source_position_from_token (token); + /* Unwind generic function template scope if necessary. */ + if (parser->fully_implicit_function_template_p) + finish_fully_implicit_template (parser, /*member_decl_opt=*/0); + if (token->type == CPP_PRAGMA) { error_at (token->location, @@ -18208,12 +18212,7 @@ cp_parser_parameter_declaration_clause (cp_parser* parser) parameter-declaration-list, then the entire parameter-declaration-clause is erroneous. */ if (is_error) - { - /* Unwind generic function template scope if necessary. */ - if (parser->fully_implicit_function_template_p) - finish_fully_implicit_template (parser, /*member_decl_opt=*/0); - return NULL; - } + return NULL; /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); diff --git a/gcc/testsuite/g++.dg/cpp1y/pr60393.C b/gcc/testsuite/g++.dg/cpp1y/pr60393.C new file mode 100644 index 0000000..38b8b91 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr60393.C @@ -0,0 +1,9 @@ +// PR c++/60393 +// { dg-options -std=c++1y } + +void (*f)(auto) + 0; // { dg-error "expected" } + +struct A +{ + int i; +};