]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: allow stores to anon union vars to change current union member in constexpr...
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Dec 2024 16:28:47 +0000 (17:28 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 11 Dec 2024 16:28:47 +0000 (17:28 +0100)
commit337815c8bbd0fb5034223ad0e7899d1493e958a2
treed045e8d21abfb483f8f4ce26ee8f761b2c195509
parent4b4023d52986b20369a0bdc9366d82c2b2f1efc7
c++: allow stores to anon union vars to change current union member in constexpr [PR117614]

Since r14-4771 the FE tries to differentiate between cases where the lhs
of a store allows changing the current union member and cases where it
doesn't, and cases where it doesn't includes everything that has gone
through the cxx_eval_constant_expression path on the lhs.
As the testcase shows, DECL_ANON_UNION_VAR_P vars were handled like that
too, even when stores to them are the only way how to change the current
union member in the sources.

So, the following patch just handles that case manually without calling
cxx_eval_constant_expression and without setting evaluated to true.

2024-12-11  Jakub Jelinek  <jakub@redhat.com>

PR c++/117614
* constexpr.cc (cxx_eval_store_expression): For stores to
DECL_ANON_UNION_VAR_P vars just continue with DECL_VALUE_EXPR
of it, without setting evaluated to true or full
cxx_eval_constant_expression.

* g++.dg/cpp2a/constexpr-union8.C: New test.
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp2a/constexpr-union8.C [new file with mode: 0644]