2020-02-04 Jason Merrill <jason@redhat.com>
+ PR c++/90951
+ * constexpr.c (cxx_eval_array_reference): {}-initialize missing
+ elements instead of value-initializing them.
+
PR c++/86917
* init.c (perform_member_init): Simplify.
* constexpr.c (cx_check_missing_mem_inits): Allow uninitialized
}
/* If it's within the array bounds but doesn't have an explicit
- initializer, it's value-initialized. */
- tree val = build_value_init (elem_type, tf_warning_or_error);
+ initializer, it's initialized from {}. But use build_value_init
+ directly for non-aggregates to avoid creating a garbage CONSTRUCTOR. */
+ tree val;
+ if (CP_AGGREGATE_TYPE_P (elem_type))
+ {
+ tree empty_ctor = build_constructor (init_list_type_node, NULL);
+ val = digest_init (elem_type, empty_ctor, tf_warning_or_error);
+ }
+ else
+ val = build_value_init (elem_type, tf_warning_or_error);
return cxx_eval_constant_expression (ctx, val, lval, non_constant_p,
overflow_p);
}
--- /dev/null
+// PR c++/90951
+// { dg-do compile { target c++11 } }
+
+#define assert(expr) static_assert (expr, #expr)
+
+struct S { const char a[2]; };
+
+constexpr struct S a[1][1][1] = { };
+
+assert ('\0' == *a[0][0][0].a);