https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110570
Bug ID: 110570 Summary: Error reading mutable subobject in constexpr when object lifetime began within the evaluation of E Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program struct S { mutable int i = 2; }; constexpr auto f = []{ constexpr S s; s.i = 3; return s.i; }; static_assert( f() == 3 ); is accepted in Clang, MSVC and ICC. But GCC rejects the code with the error in 'constexpr' expansion of 'f.<lambda()>()' error: mutable 'S::i' is not usable in a constant expression Online demo: https://gcc.godbolt.org/z/Wsfeah3hq It seems wrong, since lifetime of object s begins within the evaluation of constant expression, see https://timsong-cpp.github.io/cppwp/n4861/expr.const#5.16 Clang developers think that GCC is wrong here: https://github.com/llvm/llvm-project/issues/63695 SO question: https://stackoverflow.com/q/76608087/7325599