This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50929] [C++0x] Wrong function selected for overload with template and rvalue reference
- From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 31 Oct 2011 10:18:04 +0000
- Subject: [Bug c++/50929] [C++0x] Wrong function selected for overload with template and rvalue reference
- Auto-submitted: auto-generated
- References: <bug-50929-4@http.gcc.gnu.org/bugzilla/>
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);