This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52901] invalid rvalue reference
- From: "marc.glisse at normalesup dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 08 Apr 2012 15:32:45 +0000
- Subject: [Bug c++/52901] invalid rvalue reference
- Auto-submitted: auto-generated
- References: <bug-52901-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52901
Marc Glisse <marc.glisse at normalesup dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marc.glisse at normalesup
| |dot org
--- Comment #3 from Marc Glisse <marc.glisse at normalesup dot org> 2012-04-08 15:32:45 UTC ---
(In reply to comment #2)
> > X&& f() {
> > X x;
> > return std::move(x);
> > }
>
> This function is unsafe, it returns a reference to a local variable. You
> probably meant it to return X not X&&
>
> It is effectively the same as:
>
> X& f() {
> X x;
> return x;
> }
>
> (except G++ warns about that, because it's simpler)
Maybe this could be taken as a RFE for a warning with std::move? Many people
learning C++11 are bound to try similar things. g++ warns for
return X();
return static_cast<X&&>(x);
but not
return std::move(x);
I expect the case of std::move to be important enough that if doing a generic
warning is too hard, special-casing std::move could be worth the trouble
(assuming it is easier).