This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR c++/29731: ICE with statement expression as template parameter


Hello Mark.

Thanks for your feedback.

> But, I'm not willing to trust that the entire rest of the front end can
> deal with statement expressions outside of function bodies.  So, let's
> just give the user an error, and move on.  So, change that code to do:
>
>             if (!parser->in_function_body)
>               {
>                 error ("statement-expressions are allowed only inside
> functions");
>                 skip_to_end_of_block_or_statement (parser);
>                 expr = error_mark_node;
>              } else {
>                 /* parse it */
>              }
I had tried something like that, but with 
'cp_parser_skip_to_closing_parenthesis'; it didn't work, so I went for the 
extra bool...

Anyway, here's the revised patch, successfully regtested on i686-pc-linux-gnu 
with no new unexpected failures.

> That patch is pre-approved, after testing.
OK. I will commit it once my SVN account is setup.

Best regards,
Simon
2006-12-07  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/29731
	* parser.c (cp_parser_primary_expression): Return error_mark_node when
	a statement-expression is found outside of a function body.
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 119792)
+++ gcc/cp/parser.c	(working copy)
@@ -2998,13 +2998,20 @@ cp_parser_primary_expression (cp_parser 
 
 	       at class or namespace scope.  */
 	    if (!parser->in_function_body)
-	      error ("statement-expressions are allowed only inside functions");
-	    /* Start the statement-expression.  */
-	    expr = begin_stmt_expr ();
-	    /* Parse the compound-statement.  */
-	    cp_parser_compound_statement (parser, expr, false);
-	    /* Finish up.  */
-	    expr = finish_stmt_expr (expr, false);
+	      {
+		error ("statement-expressions are allowed only inside functions");
+		cp_parser_skip_to_end_of_block_or_statement (parser);
+		expr = error_mark_node;
+	      }
+	    else
+	      {
+		/* Start the statement-expression.  */
+		expr = begin_stmt_expr ();
+		/* Parse the compound-statement.  */
+		cp_parser_compound_statement (parser, expr, false);
+		/* Finish up.  */
+		expr = finish_stmt_expr (expr, false);
+	      }
 	  }
 	else
 	  {
2006-12-07  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/29731
	* g++.dg/parse/template22.C: New test.
/* PR c++/29731. This used to ICE in uses_template_parms. */

template<int> struct A {};

A<({})> a; /* { dg-error "forbids braced-groups within expressions|statement-expressions|template argument 1 is invalid|invalid type" } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]