public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110570] New: Error reading mutable subobject in constexpr when object lifetime began within the evaluation of E
@ 2023-07-06 7:31 fchelnokov at gmail dot com
0 siblings, 0 replies; only message in thread
From: fchelnokov at gmail dot com @ 2023-07-06 7:31 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-06 7:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 7:31 [Bug c++/110570] New: Error reading mutable subobject in constexpr when object lifetime began within the evaluation of E fchelnokov at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).