aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-12-20 23:30:04 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-12-20 23:30:04 +0000
commit14818f987abbb15c203043838e4ef9fbb20c783e (patch)
treed92d324dc4356c9a277942180fa4522b7cee4222 /gcc/cp/decl.c
parent97ba5b86a3c7afba4e53b84d40e056328c5ba5e0 (diff)
downloadgcc-14818f987abbb15c203043838e4ef9fbb20c783e.zip
gcc-14818f987abbb15c203043838e4ef9fbb20c783e.tar.gz
gcc-14818f987abbb15c203043838e4ef9fbb20c783e.tar.bz2
PR c++/92745 - bogus error when initializing array of vectors.
In r268428 I changed reshape_init_r in such a way that when it sees a nested { } in a CONSTRUCTOR with missing braces, it just returns the initializer: + else if (COMPOUND_LITERAL_P (stripped_init) ... + ++d->cur; + gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init)); + return init; But as this test shows, that's incorrect: if TYPE is an array, we need to proceed to reshape_init_array_1 which will iterate over the array initializers: 6006 /* Loop until there are no more initializers. */ 6007 for (index = 0; 6008 d->cur != d->end && (!sized_array_p || index <= max_index_cst); 6009 ++index) 6010 { and update d.cur accordingly. In other words, when reshape_init gets {{col[0][0], col[1][0], col[2][0], col[3][0]}, {col[0][1], col[1][1], col[2][1], col[3][1]}, {col[0][2], col[1][2], col[2][2], col[3][2]}, {col[0][3], col[1][3], col[2][3], col[3][3]}} we recurse on the first element: {col[0][0], col[1][0], col[2][0], col[3][0]} and we can't just move d.cur to point to {col[0][1], col[1][1], col[2][1], col[3][1]} and return; we need to iterate, so that d.cur ends up being properly updated, and after all initializers have been seen, points to d.end. Currently we skip the loop, wherefore we hit this: 6502 /* Make sure all the element of the constructor were used. Otherwise, 6503 issue an error about exceeding initializers. */ 6504 if (d.cur != d.end) 6505 { 6506 if (complain & tf_error) 6507 error ("too many initializers for %qT", type); 6508 return error_mark_node; 6509 } * decl.c (reshape_init_r): For a nested compound literal, do call reshape_init_{class,array,vector}. * g++.dg/cpp0x/initlist118.C: New test. From-SVN: r279686
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7d4c947..c15cbfa 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6399,14 +6399,13 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p,
by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
which is missing outermost braces. We should warn below, and
one of the routines below will wrap it in additional { }. */;
- /* For a nested compound literal, there is no need to reshape since
- we called reshape_init in finish_compound_literal, before calling
- digest_init. */
- else if (COMPOUND_LITERAL_P (stripped_init)
- /* Similarly, a CONSTRUCTOR of the target's type is a
- previously digested initializer. */
- || same_type_ignoring_top_level_qualifiers_p (type,
- init_type))
+ /* For a nested compound literal, proceed to specialized routines,
+ to handle initialization of arrays and similar. */
+ else if (COMPOUND_LITERAL_P (stripped_init))
+ gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
+ /* A CONSTRUCTOR of the target's type is a previously
+ digested initializer. */
+ else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
{
++d->cur;
gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));