Given all three functions, this call is ambiguous.
int f( int ); int f( int && ); int f( int const & ); int q = f( 3 );
Removing f( int ) causes Clang and GCC to prefer the rvalue link over the lvalue link. But instead, removing the two overload reference values โโin an ambiguity with f( int ) .
Overload resolution is usually done in terms of strict partial ordering, but int seems equivalent to two things that are not equivalent to each other. What are the rules here? I seem to recall a bug report.
Is it likely that int && may be preferable to int in a future standard? The link must be bound to the initializer, while the type of the object is not so limited. Therefore, an overload between T and T && can actually mean "use an existing facility if I was given ownership, otherwise make a copy." (This looks like a clean pass by value, but saves the overhead of moving.) Since these compilers are currently working, this must be done by overloading T const & and T && and explicitly copying. But I'm not even sure that this is standard.
c ++ overloading c ++ 11 rvalue-reference c ++ 14
Potatoswatter Jul 31 '13 at 4:38 2013-07-31 04:38
source share