question on template overload

Graziano Servizi Graziano.Servizi@bo.infn.it
Fri Nov 21 14:24:00 GMT 2014


Hi, everybody

I have already looked for an answer to my question on stackoverflow, 
finding this

http://stackoverflow.com/questions/13649061/manual-select-overloaded-function-for-rvalue-or-lvalue-type

and also looked among the known gcc bugs (without finding something 
useful); I have also read the standard as carefully as I can...

so the question is:

are known reasons leading the following silly code

template <typename Z> void f(Z& z) {}
template <typename Z> void f(Z&& z) {}

int main()
  {
   double x = 0;
   f(x);
   f(0.0);
   }

not being compiled by gcc 4.8.3 (without a const qualifier
in the lvalue-reference parameter of the first overload) while clang 3.4 
does?

The diagnostic says that the first function call is ambiguous:
what about partial ordering? By the way clang resolves the two function 
calls by calling the first and second overload respectively.

In stackoverflow it is said that this code is C++11 standard compliant...


Thanks for your attention.

                         G. Servizi




More information about the Gcc-help mailing list