aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-01-28 13:11:50 -0500
committerJason Merrill <jason@redhat.com>2025-01-28 17:19:02 -0500
commitc3b0b98b3ba57840ab2cfbc9d44d001c1e9167bf (patch)
treee25adef3450b177922fb415e9d97db857fcbb13d /gcc/testsuite/g++.dg/cpp0x
parentd0f230adf0e888d9218a123ac620c9a5b3020c2d (diff)
downloadgcc-c3b0b98b3ba57840ab2cfbc9d44d001c1e9167bf.zip
gcc-c3b0b98b3ba57840ab2cfbc9d44d001c1e9167bf.tar.gz
gcc-c3b0b98b3ba57840ab2cfbc9d44d001c1e9167bf.tar.bz2
c++: constexpr VEC_INIT_EXPR [PR118285]
cxx_eval_vec_init_1 was doing the wrong thing for an array of self-referential class type; just evaluating the TARGET_EXPR initializer creates a new object that refers to the TARGET_EXPR_SLOT, if we want it to refer properly to the initialization target we need to provide it. PR c++/118285 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_vec_init_1): Build INIT_EXPR for initializing a class. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-opt7.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x')
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C41
1 files changed, 41 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C b/gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C
new file mode 100644
index 0000000..f55ef5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C
@@ -0,0 +1,41 @@
+// PR c++/118285
+// { dg-do compile { target c++20 } }
+
+#include <initializer_list>
+
+struct A {
+ char *a;
+ union { char b[8]; long c; };
+ constexpr A (const char *x) : a(b)
+ {
+ for (int i = 0; i < 8; ++i)
+ b[i] = 0;
+ }
+ constexpr ~A ()
+ {
+ if (!foo ())
+ bar (c);
+ }
+ constexpr bool foo ()
+ {
+ char *x = a;
+ if (x == b)
+ return true;
+ return false;
+ }
+ constexpr void bar (long) {}
+};
+
+constexpr void
+baz (std::initializer_list<A>)
+{
+}
+
+constexpr bool
+qux ()
+{
+ baz ({""});
+ return true;
+}
+
+static_assert (qux (), "");