]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/29731 (ICE with statement expression as template parameter)
authorSimon Martin <simartin@users.sourceforge.net>
Sun, 31 Dec 2006 16:09:07 +0000 (16:09 +0000)
committerSimon Martin <simartin@gcc.gnu.org>
Sun, 31 Dec 2006 16:09:07 +0000 (16:09 +0000)
2006-12-31  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.

From-SVN: r120299

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/template22.C [new file with mode: 0644]

index 8c0e170a6da002ade7bccfdbb57c37a23c055f4f..ae5beb2a624b45bebf1e05c702e98d3929d6ac7f 100644 (file)
@@ -1,3 +1,9 @@
+2006-12-31  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.
+
 2006-12-28  Kazu Hirata  <kazu@codesourcery.com>
 
        * cp-tree.h (TYPE_NAMESPACE_SCOPE_P, TYPE_FUNCTION_SCOPE_P):
index ae2b4a028031c43e324e3bdd58a0fe4500c922b1..82cb796985890e47f42ee3c6c6e3f23a0ce56148 100644 (file)
@@ -3024,13 +3024,20 @@ cp_parser_primary_expression (cp_parser *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
          {
index a24138920b200b36e233b40450bdaba17b926f4b..df63017b96c836f36631fbca9f39ff93ec0a1aa6 100644 (file)
@@ -1,3 +1,8 @@
+2006-12-31  Simon Martin  <simartin@users.sourceforge.net>
+
+       PR c++/29731
+       * g++.dg/parse/template22.C: New test.
+
 2006-12-31  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/30338
diff --git a/gcc/testsuite/g++.dg/parse/template22.C b/gcc/testsuite/g++.dg/parse/template22.C
new file mode 100644 (file)
index 0000000..c933756
--- /dev/null
@@ -0,0 +1,5 @@
+/* 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" } */