aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-04-08 15:33:41 -0400
committerJason Merrill <jason@redhat.com>2022-04-08 23:25:54 -0400
commit4822108e61ab879067482704f2f7d1670813d61a (patch)
treee3b0b52a7cca145a83283d6024a4963de68ce0c8 /gcc/cp/constexpr.cc
parent58586721c79f77224b8571a5dba732620d5546ab (diff)
downloadgcc-4822108e61ab879067482704f2f7d1670813d61a.zip
gcc-4822108e61ab879067482704f2f7d1670813d61a.tar.gz
gcc-4822108e61ab879067482704f2f7d1670813d61a.tar.bz2
c++: constexpr non-trivial aggregate init [PR105191]
My patch for PR92385 made us use VEC_INIT_EXPR for aggregate initialization of an array where some elements are not explicitly initialized. Constexpr handling of that was treating initialization from {} as equivalent to value-initialization, which is problematic for classes with default member initializers that make the default constructor non-trivial; in older standard modes, not initializing all members makes a constructor non-constexpr, but aggregate initialization is fine. PR c++/105191 PR c++/92385 gcc/cp/ChangeLog: * tree.cc (build_vec_init_elt): Do {}-init for aggregates. * constexpr.cc (cxx_eval_vec_init): Only treat {} as value-init for non-aggregate types. (build_vec_init_expr): Also check constancy of explicit initializer elements. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-array28.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 9c40b05..db78b4a 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -5008,7 +5008,8 @@ cxx_eval_vec_init (const constexpr_ctx *ctx, tree t,
bool value_init = VEC_INIT_EXPR_VALUE_INIT (t);
if (!init || !BRACE_ENCLOSED_INITIALIZER_P (init))
;
- else if (CONSTRUCTOR_NELTS (init) == 0)
+ else if (CONSTRUCTOR_NELTS (init) == 0
+ && !CP_AGGREGATE_TYPE_P (strip_array_types (atype)))
{
/* Handle {} as value-init. */
init = NULL_TREE;