]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: empty union member activation during constexpr [PR102163]
authorPatrick Palka <ppalka@redhat.com>
Tue, 14 Sep 2021 15:22:12 +0000 (11:22 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 14 Sep 2021 15:22:12 +0000 (11:22 -0400)
commitde07cff96abd43f6f65dcf333958899c2ec42598
tree05fbbb6484dff791c6a2a5fd8f82ad60ba12fe00
parent818c505188ff5cd8eb048eb0e614c4ef732225bd
c++: empty union member activation during constexpr [PR102163]

Here, the union's constructor is defined to activate its empty data
member _M_rest, but during constexpr evaluation of this constructor the
subobject constructor call O::O(&_M_rest, 42) doesn't produce a side
effect that actually activates the member, so the union still appears
uninitialized after its constructor has run.  This patch fixes this by
using a dummy MODIFY_EXPR in this situation, whose evaluation ensures
the member gets activated.

PR c++/102163

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_call_expression): After evaluating a
subobject constructor call for an empty union member, produce a
side effect that makes sure the member gets activated.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-empty17.C: New test.
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-empty17.C [new file with mode: 0644]