This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] Fix PR c/27489 and c/27490 compound expression and parse error
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Aug 2006 18:41:41 -0700
- Subject: [Committed] Fix PR c/27489 and c/27490 compound expression and parse error
The problem here is that when we have a parse error (error_mark_node)
for a compound expression, we create a compound expression still instead
just returning error_mark_node. This fixes the problem by just
returning error_mark_node instead of letting the other parts of the
front-end dealing with compound expression having error_mark_node in it.
Applied to the mainline as approved by JSM in PR 27489.
I will apply this to the 4.1 branch in about a week also.
Thanks,
Andrew Pinski
ChangeLog:
* c-typeck.c (build_compound_expr): If the second expression
is an error mark, then just return an error mark instead of
creating a COMPOUND_EXPR.
testsuite/ChangeLog:
* gcc.dg/sizeof-2.c: New testcase.
* gcc.dg/switch-A.c: New testcase.
Index: testsuite/gcc.dg/switch-A.c
===================================================================
--- testsuite/gcc.dg/switch-A.c (revision 0)
+++ testsuite/gcc.dg/switch-A.c (revision 0)
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+
+void foo()
+{
+ switch (,) { } /* { dg-error "expected expression before" } */
+}
+
Index: testsuite/gcc.dg/sizeof-2.c
===================================================================
--- testsuite/gcc.dg/sizeof-2.c (revision 0)
+++ testsuite/gcc.dg/sizeof-2.c (revision 0)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+
+
+void foo()
+{
+ sizeof(,); /* { dg-error "expected expression before" } */
+}
+
Index: c-typeck.c
===================================================================
--- c-typeck.c (revision 116125)
+++ c-typeck.c (working copy)
@@ -3425,6 +3425,9 @@ build_compound_expr (tree expr1, tree ex
else if (warn_unused_value)
warn_if_unused_value (expr1, input_location);
+ if (expr2 == error_mark_node)
+ return error_mark_node;
+
return build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
}