aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-02-01 17:23:53 -0500
committerJason Merrill <jason@redhat.com>2024-02-01 22:22:06 -0500
commitf4998609908e4926fc095ce97cb84b187294fd1d (patch)
treedbb5fc97845831fc32c5fbe38da794a9d77a340f /gcc
parent0b786ff38ab398087820d91241e030a28c451df9 (diff)
downloadgcc-f4998609908e4926fc095ce97cb84b187294fd1d.zip
gcc-f4998609908e4926fc095ce97cb84b187294fd1d.tar.gz
gcc-f4998609908e4926fc095ce97cb84b187294fd1d.tar.bz2
c++: no_unique_address and constexpr [PR112439]
Here, because we don't build a CONSTRUCTOR for an empty base, we were wrongly marking the Foo CONSTRUCTOR as complete after initializing the Empty member. Fixed by checking empty_base here as well. PR c++/112439 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_store_expression): Check empty_base before marking a CONSTRUCTOR readonly. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/no_unique_address15.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/constexpr.cc1
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C19
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 6350fe154..2ebb147 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -6694,6 +6694,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
object. Make a note of this fact by marking the CONSTRUCTOR
TREE_READONLY. */
if (TREE_CODE (t) == INIT_EXPR
+ && !empty_base
&& TREE_CODE (*valp) == CONSTRUCTOR
&& TYPE_READONLY (type))
{
diff --git a/gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C b/gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C
new file mode 100644
index 0000000..3e7cf08
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/no_unique_address15.C
@@ -0,0 +1,19 @@
+// PR c++/112439
+// { dg-do compile { target c++14 } }
+
+struct Empty {};
+
+class Foo {
+public:
+ constexpr Foo(int x, Empty y, int z) : a(x), b(y)
+ {
+ c = z;
+ }
+
+private:
+ int a{};
+ [[no_unique_address]] Empty b{};
+ [[no_unique_address]] int c{};
+};
+
+constexpr Foo r{1, {}, 3};