]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/21873 (infinite warning loop on bad array initializer)
authorJoseph Myers <joseph@codesourcery.com>
Thu, 28 Jul 2005 22:56:03 +0000 (23:56 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Thu, 28 Jul 2005 22:56:03 +0000 (23:56 +0100)
PR c/21873
* c-typeck.c (push_init_level): Don't pop levels without braces if
implicit == 1.

testsuite:
* gcc.dg/init-excess-1.c: New test.

From-SVN: r102525

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog

index 37dae8975fb9bec1375938147b59f6aa7e553223..c0b6b05577fdadba53fa8e681270212b985112bf 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-28  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/21873
+       * c-typeck.c (push_init_level): Don't pop levels without braces if
+       implicit == 1.
+
 2005-07-28  Gerald Pfeifer  <gerald@pfeifer.com>
   
        * doc/install.texi (Configuration): Update Valgrind homepage.
index c9479f08d12744fdd34574c1e2205f22d5d11a24..3da121e10f9eb8a612cf9a71cece839ddd960425 100644 (file)
@@ -4634,19 +4634,27 @@ push_init_level (int implicit)
   tree value = NULL_TREE;
 
   /* If we've exhausted any levels that didn't have braces,
-     pop them now.  */
-  while (constructor_stack->implicit)
+     pop them now.  If implicit == 1, this will have been done in
+     process_init_element; do not repeat it here because in the case
+     of excess initializers for an empty aggregate this leads to an
+     infinite cycle of popping a level and immediately recreating
+     it.  */
+  if (implicit != 1)
     {
-      if ((TREE_CODE (constructor_type) == RECORD_TYPE
-          || TREE_CODE (constructor_type) == UNION_TYPE)
-         && constructor_fields == 0)
-       process_init_element (pop_init_level (1));
-      else if (TREE_CODE (constructor_type) == ARRAY_TYPE
-              && constructor_max_index
-              && tree_int_cst_lt (constructor_max_index, constructor_index))
-       process_init_element (pop_init_level (1));
-      else
-       break;
+      while (constructor_stack->implicit)
+       {
+         if ((TREE_CODE (constructor_type) == RECORD_TYPE
+              || TREE_CODE (constructor_type) == UNION_TYPE)
+             && constructor_fields == 0)
+           process_init_element (pop_init_level (1));
+         else if (TREE_CODE (constructor_type) == ARRAY_TYPE
+                  && constructor_max_index
+                  && tree_int_cst_lt (constructor_max_index,
+                                      constructor_index))
+           process_init_element (pop_init_level (1));
+         else
+           break;
+       }
     }
 
   /* Unless this is an explicit brace, we need to preserve previous
index e9f90da27348f4f5ceaa024e63246e988be39031..b1df1c2a64101757c25606913f328be5919114a4 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-28  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/21873
+       * gcc.dg/init-excess-1.c: New test.
+
 2005-07-28  Richard Sandiford  <richard@codesourcery.com>
 
        PR c/20187