This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36744] function modifying argument received by-value affects caller's variable when passed as rvalue
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Jan 2009 17:25:02 -0000
- Subject: [Bug c++/36744] function modifying argument received by-value affects caller's variable when passed as rvalue
- References: <bug-36744-5473@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #5 from rguenth at gcc dot gnu dot org 2009-01-31 17:25 -------
Confirmed.
struct S
{
S(): i(2) {}
S(S const&);
int i;
};
void f(S x) { x.i = 0; }
extern "C" void abort (void);
int main()
{
S y;
f(static_cast<S&&>(y));
if (y.i != 2)
abort ();
return 0;
}
declaring S(S const&); makes f() take a reference type and neither the
caller nor the callee performs a copy before writing to the passed by value y.
declaring S(S const&&); does not have this effect.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Known to fail| |4.4.0
Last reconfirmed|0000-00-00 00:00:00 |2009-01-31 17:25:01
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36744