diff mbox

Fix PR c++/60393

Message ID 1393969569-5509-1-git-send-email-adam@jessamine.co.uk
State New
Headers show

Commit Message

Adam Butcher March 4, 2014, 9:46 p.m. UTC
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.

	PR c++/60393
	* g++.dg/cpp1y/pr60393.C: New testcase.
---
 gcc/cp/parser.c                      | 11 +++++------
 gcc/testsuite/g++.dg/cpp1y/pr60393.C |  9 +++++++++
 2 files changed, 14 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr60393.C

Comments

Jason Merrill March 7, 2014, 5:29 p.m. UTC | #1
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
Adam Butcher March 7, 2014, 7:10 p.m. UTC | #2
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.
Jason Merrill March 7, 2014, 7:59 p.m. UTC | #3
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 mbox

Patch

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;
+};