aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-02-26 15:37:39 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-02-26 15:37:39 +0100
commitc7f7c313c0da09232ced316ebb9806bd0f70405c (patch)
tree042a5de16a25d6b84a493f189ce6d45b60833c41 /gcc
parent01c3ddcffb38e92e0f59aeb270e4848a5b8941f0 (diff)
downloadgcc-c7f7c313c0da09232ced316ebb9806bd0f70405c.zip
gcc-c7f7c313c0da09232ced316ebb9806bd0f70405c.tar.gz
gcc-c7f7c313c0da09232ced316ebb9806bd0f70405c.tar.bz2
re PR c++/89481 (constexpr function allows writing one active union member and reading another)
PR c++/89481 * constexpr.c (cxx_eval_store_expression): When changing active union member, set no_zero_init. * g++.dg/cpp1y/constexpr-89481.C: New test. From-SVN: r269213
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C24
4 files changed, 36 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2da2e3d..6344e4e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2019-02-26 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/89481
+ * constexpr.c (cxx_eval_store_expression): When changing active union
+ member, set no_zero_init.
+
2019-02-23 Marek Polacek <polacek@redhat.com>
PR c++/88294 - ICE with non-constant noexcept-specifier.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 4008027..5bc5efe 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3860,6 +3860,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
}
/* Changing active member. */
vec_safe_truncate (CONSTRUCTOR_ELTS (*valp), 0);
+ no_zero_init = true;
}
for (idx = 0;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3f76c45..4317ad8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-26 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/89481
+ * g++.dg/cpp1y/constexpr-89481.C: New test.
+
2019-02-26 Richard Biener <rguenther@suse.de>
PR tree-optimization/89505
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C
new file mode 100644
index 0000000..8ac4ef0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-89481.C
@@ -0,0 +1,24 @@
+// PR c++/89481
+// { dg-do compile { target c++14 } }
+
+constexpr int
+foo ()
+{
+ union U { long long a; int b[2]; } u { 5LL };
+ u.b[1] = 4; // { dg-error "change of the active member of a union from" "" { target c++17_down } }
+ return u.b[0];
+}
+
+constexpr int
+bar ()
+{
+ union U { long long a; int b[2]; } u { 5LL };
+ u.b[1] = 4; // { dg-error "change of the active member of a union from" "" { target c++17_down } }
+ return u.b[1];
+}
+
+static_assert (foo () == 0, ""); // { dg-error "non-constant condition for static assertion" }
+ // { dg-message "in 'constexpr' expansion of" "" { target *-*-* } .-1 }
+ // { dg-error "accessing uninitialized array element" "" { target c++2a } .-2 }
+static_assert (bar () == 4, ""); // { dg-error "non-constant condition for static assertion" "" { target c++17_down } }
+ // { dg-message "in 'constexpr' expansion of" "" { target c++17_down } .-1 }