[Bug c++/50929] [C++0x] Wrong function selected for overload with template and rvalue reference
daniel.kruegler at googlemail dot com
gcc-bugzilla@gcc.gnu.org
Mon Oct 31 10:18:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50929
--- Comment #5 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-10-31 10:18:04 UTC ---
(In reply to comment #4)
> I didn't realise that A(A&) was a better match. I was thinking of C++ code
> where you might write:
>
> template <typename T>
> A(const T& t);
>
> A(const A& rhs);
>
> in which case A(const A&) would be chosen.
Sure. But if you had provided
template <typename T>
A(T& t);
instead that would again be a better match for a non-const A lvalue.
Non-template functions only win over templates, if they are otherwise equal in
matching.
> I didn't realise that the rvalue reference puts a spanner in the works.
Note that "rvalue-reference" is a red herring for the perfect-forwarding
signature
template <typename T>
A(T&& t);
It depends on whether the argument is an lvalue or not to decide whether the
finally deduced type is effectively A& or A&& (or whatever argument type had
been provided). In your example the argument was an lvalue of type A, therefore
the deduced signature was effectively
template <> A(A& t);
More information about the Gcc-bugs
mailing list