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: "michal at rzechonek dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Jan 2009 16:58:44 -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 #4 from michal at rzechonek dot net 2009-01-31 16:58 -------
I think that this bug is related to failure in code below:
class movable {
int resource; // 0=not acquired
movable(const movable&); // no copy c'tor
void operator=(const movable&); // no copy-assignment
public:
explicit movable(int i=0) : resource(i) {}
int get() const {return resource;}
int release() {int r=resource; resource=0; return r;}
movable(movable && rval) : resource(rval.release())
{ cout << "movable::movable(movable &&)" << endl;}
};
void sink(movable m) {
cout << "sink: &m --> " << &m << endl;
cout << "sink: m.get() --> " << m.get() << endl;
}
int main() {
movable m (42);
cout << "main: &m --> " << &m << endl;
sink(move(m));
assert(m.get()==0);
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36744