Created on 2007-12-01.00:00:00 last changed 178 months ago
[Voted into WP at March, 2010 meeting as document N3055.]
Proposed resolution (February, 2010):
See paper N3030.
Notes from the February, 2008 meeting:
You can't just treat scalar rvalues like class and array rvalues, because they might not have an associated object. However, if you have an rvalue reference, you know that there is an object, so probably the best way to address this issue is to specify somehow that binding a reference to an rvalue reference does not introduce a new temporary.
According to 9.4.4 [dcl.init.ref] paragraph 5, a reference initialized with a reference-compatible rvalue of class type binds directly to the object. A reference-compatible non-class rvalue reference, however, is first copied to a temporary and the reference binds to that temporary, not to the target of the rvalue reference. This can cause problems when the result of a forwarding function is used in such a way that the address of the result is captured. For example:
struct ref { explicit ref(int&& i): p(&i) { } int* p; }; int&& forward(int&& i) { return i; } void f(int&& i) { ref r(forward(i)); // Here r.p is a dangling pointer, pointing to a defunct int temporary }
A formulation is needed so that rvalue references are treated like class and array rvalues.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-03-29 00:00:00 | admin | set | messages: + msg2712 |
2010-03-29 00:00:00 | admin | set | status: review -> cd2 |
2010-02-16 00:00:00 | admin | set | messages: + msg2544 |
2010-02-16 00:00:00 | admin | set | status: drafting -> review |
2008-03-17 00:00:00 | admin | set | messages: + msg1607 |
2008-03-17 00:00:00 | admin | set | status: open -> drafting |
2007-12-01 00:00:00 | admin | create |