https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90638

--- Comment #6 from Igor Smirnov <Igor.Smirnov at cern dot ch> ---
Mark, thank you for useful advice.

So, my conclusion is that the rules for resolution in the presence of 
function templates are not changed in gcc. For all versions of C++ 
the result generated by this site was the same. The program is compiled without 
"call ... is ambiguous" complaints, and calls the variant of the function 
for "int" argument when called with long double: 

fun(1.1, 1)=
fun(T,  int) is working.
1.1
fun(1.1, 1/2.0)=
fun(T, const T&) is working.
0.55
fun(1.1, (long double)1/2.0)=
fun(T,  int) is working.
0

This behaviour is counter to logic because an identical program with 
with almost identical ordinary functions is NOT compiled with complaint
"prog.cc:21:28: error: call of overloaded 'fun(double, double)' is ambiguous",
see an example below.
Since the user may not even know that the functions are template
(an ordinary function can depend on agruments having a fully specified 
template type), he may not notice this error. 

--------------------------------------------------------------------

#include <iostream>

double fun(double x, int i)
{
  std::cout<<"fun(double,  int) is working.\n";
  return x * i;
}

double fun(double x, const long double& d)
{
  std::cout<<"fun(double, const long double&) is working.\n";
  return x * d;
}

int main(void)
{
  std::cout<<"fun(1.1, 1)="<<'\n';
  std::cout<<fun(1.1, 1)<<'\n';

  std::cout<<"fun(1.1, 1/2.0)="<<'\n';
  std::cout<<fun(1.1, 1/2.0)<<'\n';

  std::cout<<"fun(1.1, (long double)1/2.0)="<<'\n';
  std::cout<<fun(1.1, (long double)1/2.0)<<'\n';
}
---------------------------------------------------------------------

Reply via email to