c++: 'mutable' member within constexpr [PR92505]
authorPatrick Palka <ppalka@redhat.com>
Fri, 16 Sep 2022 15:10:43 +0000 (11:10 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 16 Sep 2022 15:10:43 +0000 (11:10 -0400)
commit7107ea6fb933f1e928593c7e92edfd64ccf0df63
tree44af7a855317b9a75d2fd9d6aaf7436c1f88ea31
parentb6adc6255f527edd50c08c4aacb4ee21df1c349c
c++: 'mutable' member within constexpr [PR92505]

This patch permits accessing 'mutable' members of local objects during
constexpr evaluation, while continuing to reject it for global objects
(as in the last line of cpp0x/constexpr-mutable1.C).  To distinguish
between the two cases, it looks like it suffices to just check
CONSTRUCTOR_MUTABLE_POSION in cxx_eval_component_reference before
deciding to reject a DECL_MUTABLE_P member access.

PR c++/92505

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_component_reference): Check non_constant_p
sooner.  In C++14 or later, reject a DECL_MUTABLE_P member access
only if CONSTRUCTOR_MUTABLE_POISION is also set.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-mutable3.C: New test.
* g++.dg/cpp1y/constexpr-mutable1.C: New test.
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-mutable3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-mutable1.C [new file with mode: 0644]