https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77733
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2016-09-28 Ever confirmed|0 |1 --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- The location for the "cannot bind rvalue reference" error is not a rich location, so I couldn't figure out how to add a proper fix-it. This just adds "did you mean std::move(x)?" to the end: --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6804,7 +6804,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, if (TYPE_REF_IS_RVALUE (ref_type) && lvalue_p (expr)) error_at (loc, "cannot bind rvalue reference of type %qT to " - "lvalue of type %qT", totype, extype); + "lvalue of type %qT; did you mean %<std::move(%E)%>?", + totype, extype, expr); else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr) && !CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type))) error_at (loc, "cannot bind non-const lvalue reference of " Of course sometimes std::move is not the right fix, and it should be std::forward<something>(x) instead. Maybe it would be possible to detect whether the expression is a function parameter declared as a forwarding reference, but that's probably beyond my ken. Also, if the lvalue is cv-qualified this still suggests std::move(x) even when that wouldn't work: move2.cc:13:9: error: cannot bind rvalue reference of type ‘X&&’ to lvalue of type ‘const X’; did you mean ‘std::move(x)’? There's room for improvement.