Retro C++ quiz #55
Given the following in C++:
void f(int);
void f(short);
void f(long);
And the call to f() below:
void g(){
f(0u);
}
Assuming LP64, which f() is chosen:
A. f(int)
B. f(short)
C. f(long)
D. ambiguous can’t choose
Retro C++ quiz #55
Given the following in C++:
void f(int);
void f(short);
void f(long);
And the call to f() below:
void g(){
f(0u);
}
Assuming LP64, which f() is chosen:
A. f(int)
B. f(short)
C. f(long)
D. ambiguous can’t choose
The answer is D this is ambiguous
Overload resolution [over.match]p2
https://eel.is/c++draft/over.match#general-2
is going to find the candidates and then determine the best viable function based on implicit conversion sequence.
Promotion does not help since we have an unsigned int and int can not represent all the values so we end up with unsigned int:
http://eel.is/c++draft/conv.prom#2
So we are left with conversions:
http://eel.is/c++draft/conv.integral#1
We can convert unsigned int to short, int or long but none of these is better than the others so it is ambiguous and therefore ill-formed: