return new_init;
}
+/* Subroutine of reshape_init_r. We're in a context where C99 initializer
+ designators are not valid; either complain or return true to indicate
+ that reshape_init_r should return error_mark_node. */
+
+static bool
+has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
+{
+ if (d->cur->index)
+ {
+ if (complain & tf_error)
+ error ("C99 designator %qE outside aggregate initializer",
+ d->cur->index);
+ else
+ return true;
+ }
+ return false;
+}
+
/* Subroutine of reshape_init, which processes a single initializer (part of
a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
iterator within the CONSTRUCTOR which points to the initializer to process.
if (error_operand_p (init))
return error_mark_node;
+ if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
+ && has_designator_problem (d, complain))
+ return error_mark_node;
+
if (TREE_CODE (type) == COMPLEX_TYPE)
{
/* A complex type can be initialized from one or two initializers,
VEC(constructor_elt, gc) *v = 0;
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, d->cur->value);
+ if (has_designator_problem (d, complain))
+ return error_mark_node;
d->cur++;
init = build_constructor (init_list_type_node, v);
}
array types (one value per array element). */
if (TREE_CODE (str_init) == STRING_CST)
{
+ if (has_designator_problem (d, complain))
+ return error_mark_node;
d->cur++;
return str_init;
}
--- /dev/null
+// PR c++/51458
+// { dg-options "" }
+
+char g[] = { [7] = "abcd" }; // { dg-error "designator" }
+int a = { .foo = 6 }; // { dg-error "designator" }
+int b = { [0] = 1 }; // { dg-error "designator" }
+_Complex float c = { .foo = 0, 1 }; // { dg-error "designator" }
+_Complex float d = { [0] = 0, 1 }; // { dg-error "designator" }
+_Complex float e = { 0, .foo = 1 }; // { dg-error "designator" }
+_Complex float f = { 0, [0] = 1 }; // { dg-error "designator" }