This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to avoid excess errors for invalid initializers
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 5 Nov 2004 22:22:00 +0000 (UTC)
- Subject: Patch to avoid excess errors for invalid initializers
It doesn't make sense to give extra errors about an initializer being
non-constant when an error has already been given for that
initializer; the intended correct initializer might or might not have
been constant. Previously, we gave such excess errors in the second
case in the included testcase, but not in the first. This patch stops
such errors being given. It prevents some such excess errors in the
testsuite with the new parser's slightly different error recovery from
syntactically invalid initializers and is separated out from the last
parser patch version.
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
2004-11-05 Joseph S. Myers <joseph@codesourcery.com>
* c-typeck.c (output_init_element): Return early if value is
error_mark_node.
testsuite:
2004-11-05 Joseph S. Myers <joseph@codesourcery.com>
* gcc.dg/init-undef-1.c: New test.
diff -rupN GCC.orig/gcc/c-typeck.c GCC/gcc/c-typeck.c
--- GCC.orig/gcc/c-typeck.c 2004-10-31 10:17:52.000000000 +0000
+++ GCC/gcc/c-typeck.c 2004-11-04 20:39:35.000000000 +0000
@@ -5663,7 +5663,7 @@ static void
output_init_element (tree value, bool strict_string, tree type, tree field,
int pending)
{
- if (type == error_mark_node)
+ if (type == error_mark_node || value == error_mark_node)
{
constructor_erroneous = 1;
return;
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/init-undef-1.c GCC/gcc/testsuite/gcc.dg/init-undef-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-undef-1.c 1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-undef-1.c 2004-11-05 15:40:37.000000000 +0000
@@ -0,0 +1,8 @@
+/* Invalid initializers should not receive an "is not constant"
+ error. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int p = c; /* { dg-error "undeclared" } */
+struct s { int a; } x = { b }; /* { dg-error "undeclared" } */