aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-11-11 22:03:53 -0500
committerJason Merrill <jason@redhat.com>2021-11-15 02:49:51 -0500
commitbd95d75f3412e1a7debab7c6c602ba409f274eb5 (patch)
tree863b4a8caeabd36dc1542a590976dd45fedc453b /gcc/cp
parent4df7f8c79835d56928f51f9e674d326300936e8e (diff)
downloadgcc-bd95d75f3412e1a7debab7c6c602ba409f274eb5.zip
gcc-bd95d75f3412e1a7debab7c6c602ba409f274eb5.tar.gz
gcc-bd95d75f3412e1a7debab7c6c602ba409f274eb5.tar.bz2
c++: c++20 constexpr default ctor and array init
The implicit constexpr patch revealed that marking the constructor in the PR70690 testcase as constexpr made the bug reappear, because build_vec_init assumed that a constexpr default constructor initialized the whole object, so it was equivalent to value-initialization. But this is no longer true in C++20. PR c++/70690 gcc/cp/ChangeLog: * init.c (build_vec_init): Check default_init_uninitialized_part in C++20. gcc/testsuite/ChangeLog: * g++.dg/init/array41a.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/init.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 771a19b..3ba2e3b 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -4470,11 +4470,14 @@ build_vec_init (tree base, tree maxindex, tree init,
We do need to keep going if we're copying an array. */
- if (try_const && !init)
+ if (try_const && !init
+ && (cxx_dialect < cxx20
+ || !default_init_uninitialized_part (inner_elt_type)))
/* With a constexpr default constructor, which we checked for when
setting try_const above, default-initialization is equivalent to
value-initialization, and build_value_init gives us something more
- friendly to maybe_constant_init. */
+ friendly to maybe_constant_init. Except in C++20 and up a constexpr
+ constructor need not initialize all the members. */
explicit_value_init_p = true;
if (from_array
|| ((type_build_ctor_call (type) || init || explicit_value_init_p)