This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36744] New: function modifying argument received by-value affects caller's variable when passed as rvalue
- From: "gcc-bugzilla at contacts dot eelis dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2008 14:46:42 -0000
- Subject: [Bug c++/36744] New: function modifying argument received by-value affects caller's variable when passed as rvalue
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider:
#include <iostream>
struct S
{
S(): i(2) {}
S(S const&) {}
int i;
};
void f(S x) { x.i = 0; }
int main()
{
S y;
f(static_cast<S&&>(y));
std::cout << y.i << '\n';
}
Expected output: 2
Actual output: 0
Thus, the assignment to the independent local variable x in f somehow modifies
y. That can't be right, not even with that static_cast to S&&, can it?
--
Summary: function modifying argument received by-value affects
caller's variable when passed as rvalue
Product: gcc
Version: 4.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gcc-bugzilla at contacts dot eelis dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36744