aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/init.c7
-rw-r--r--gcc/testsuite/g++.dg/init/array41a.C27
2 files changed, 32 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)
diff --git a/gcc/testsuite/g++.dg/init/array41a.C b/gcc/testsuite/g++.dg/init/array41a.C
new file mode 100644
index 0000000..aa9fdc6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/array41a.C
@@ -0,0 +1,27 @@
+// PR c++/70690
+// { dg-do run { target c++11 } }
+
+struct A {
+ constexpr A() {}
+};
+
+struct APadded : public A {
+ char pad[63];
+};
+
+int f();
+int i = f();
+APadded cache[50];
+APadded *p = cache;
+
+int f()
+{
+ cache[0].pad[0] = 42;
+ return 1;
+}
+
+int main()
+{
+ if (cache[0].pad[0] != 42)
+ __builtin_abort();
+}