diff options
author | Joseph Myers <joseph@codesourcery.com> | 2005-06-04 02:34:47 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2005-06-04 02:34:47 +0100 |
commit | 472d98b46bfc898a1d3b2d68d9697f8c476311d4 (patch) | |
tree | d222a657cc3d23d45bb5bef331c55e2171867174 /gcc/c-typeck.c | |
parent | ecb83da78366e14defb51f41777d41ea0ede0a26 (diff) | |
download | gcc-472d98b46bfc898a1d3b2d68d9697f8c476311d4.zip gcc-472d98b46bfc898a1d3b2d68d9697f8c476311d4.tar.gz gcc-472d98b46bfc898a1d3b2d68d9697f8c476311d4.tar.bz2 |
re PR c/21873 (infinite warning loop on bad array initializer)
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: r100571
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r-- | gcc/c-typeck.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 694eb69..9d41433 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -4844,19 +4844,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 |