This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/40295] [C++0x] rvalue-references and builtin types
- From: "jwakely dot gcc at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 May 2009 17:08:05 -0000
- Subject: [Bug c++/40295] [C++0x] rvalue-references and builtin types
- References: <bug-40295-5876@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #1 from jwakely dot gcc at gmail dot com 2009-05-29 17:08 -------
This is independent of std::move
#include <cassert>
struct S
{
S() : buf(5) { }
int&& get() { return static_cast<int&&>(buf); }
int buf;
};
int main()
{
S s;
int&& r = s.get();
assert( &r == &s.buf );
}
tmpret.cc: In member function ?int&& S::get()?:
tmpret.cc:7: warning: returning reference to temporary
tmpret: tmpret.cc:16: int main(): Assertion `&r == &s.buf' failed.
Looks like the cast to int&& creates a temporary, which is bound to the
returned reference, triggering the warning. According to 8.5.3 [dcl.init.ref]
paragraph 5, the reference should be bound to the object, not to a temporary.
--
jwakely dot gcc at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|libstdc++ |c++
Keywords| |wrong-code
Summary|[C++0x] std::move and |[C++0x] rvalue-references
|builtin types |and builtin types
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40295