public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112794] New: [contracts] modifying return value fails
@ 2023-11-30 22:56 jason at gcc dot gnu.org
2023-12-02 14:10 ` [Bug c++/112794] " jason at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: jason at gcc dot gnu.org @ 2023-11-30 22:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112794
Bug ID: 112794
Summary: [contracts] modifying return value fails
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jason at gcc dot gnu.org
Target Milestone: ---
Both asserts should pass. f1 seems to fail because we pass a copy of r to
mutate instead of r itself; the .gimple dump for f2 looks fine but the
optimizers get confused for some reason.
#include <cassert>
bool mutate(const int &i) {
const_cast<int&>(i) = 42;
return true;
}
int f1()
[[ post r: mutate(r) ]]
{
return 0;
}
struct S {
S(int i) : i(i) {}
S(S&&) = delete; // non-moveable
int i;
};
bool mutate(const S& s) {
const_cast<S&>(s).i = 42;
return true;
}
S f2()
[[ post r: mutate(r) ]]
{
return S{0};
}
int main() {
assert(f1() == 42); // Fails.
assert(f2().i == 42); // Passes at -O0, ICEs at -O1, fails at -O2.
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/112794] [contracts] modifying return value fails
2023-11-30 22:56 [Bug c++/112794] New: [contracts] modifying return value fails jason at gcc dot gnu.org
@ 2023-12-02 14:10 ` jason at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: jason at gcc dot gnu.org @ 2023-12-02 14:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112794
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-12-02
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-02 14:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 22:56 [Bug c++/112794] New: [contracts] modifying return value fails jason at gcc dot gnu.org
2023-12-02 14:10 ` [Bug c++/112794] " jason at gcc dot gnu.org
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).