diff options
author | Jason Merrill <jason@redhat.com> | 2012-09-05 00:17:12 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2012-09-05 00:17:12 -0400 |
commit | faddc0d7c2d9647a4e2fa897743442dd71180d88 (patch) | |
tree | 36dc2af022600dcf76a8c66d9d71bf136af723ba /gcc/cp | |
parent | 5a706c322d07f1c834b4120fd98d943b806b4228 (diff) | |
download | gcc-faddc0d7c2d9647a4e2fa897743442dd71180d88.zip gcc-faddc0d7c2d9647a4e2fa897743442dd71180d88.tar.gz gcc-faddc0d7c2d9647a4e2fa897743442dd71180d88.tar.bz2 |
re PR c++/54441 (Infinite loop with brace initializer on zero-length array)
PR c++/54441
* decl.c (reshape_init_class): Handle invalid initializer for
0-length array member.
* error.c (dump_type_suffix): Correct handling of 0-length arrays.
From-SVN: r190962
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/decl.c | 10 | ||||
-rw-r--r-- | gcc/cp/error.c | 4 |
3 files changed, 19 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4501217..629ab57 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2012-09-04 Jason Merrill <jason@redhat.com> + PR c++/54441 + * decl.c (reshape_init_class): Handle invalid initializer for + 0-length array member. + + * error.c (dump_type_suffix): Correct handling of 0-length arrays. + PR c++/54420 * cp-tree.h (LAMBDANAME_P): Remove. (LAMBDA_TYPE_P): Check CLASSTYPE_LAMBDA_EXPR instead. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8024373..b665fe8 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5094,6 +5094,7 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, while (d->cur != d->end) { tree field_init; + constructor_elt *old_cur = d->cur; /* Handle designated initializers, as an extension. */ if (d->cur->index) @@ -5130,6 +5131,15 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, if (field_init == error_mark_node) return error_mark_node; + if (d->cur->index && d->cur == old_cur) + { + /* This can happen with an invalid initializer for a flexible + array member (c++/54441). */ + if (complain & tf_error) + error ("invalid initializer for %q#D", field); + return error_mark_node; + } + CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init); /* [dcl.init.aggr] diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 80a145d..1872d01 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -846,7 +846,9 @@ dump_type_suffix (tree t, int flags) { tree dtype = TYPE_DOMAIN (t); tree max = TYPE_MAX_VALUE (dtype); - if (host_integerp (max, 0)) + if (integer_all_onesp (max)) + pp_character (cxx_pp, '0'); + else if (host_integerp (max, 0)) pp_wide_integer (cxx_pp, tree_low_cst (max, 0) + 1); else if (TREE_CODE (max) == MINUS_EXPR) dump_expr (TREE_OPERAND (max, 0), |