mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 12:00:11 -05:00
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.
17 lines
243 B
C
17 lines
243 B
C
// PR c++/92505
|
|
// { dg-do compile { target c++14 } }
|
|
|
|
struct S { mutable int m; };
|
|
|
|
static_assert(S{42}.m == 42, "");
|
|
|
|
constexpr int f() {
|
|
S s = {40};
|
|
s.m++;
|
|
const auto& cs = s;
|
|
++cs.m;
|
|
return cs.m;
|
|
}
|
|
|
|
static_assert(f() == 42, "");
|