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

#Cplusplus
#Cpppolls

A
56.3%
B
0%
C
31.3%
D
12.5%
Poll ended at .

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:

https://eel.is/c++draft/over.match#best.general-3

[over.match]

@shafik These polls are unique in that I can take momentary pleasure that I chose the same thing as most respondents... but still have no faith at all that I'm right.
@shafik I didn't expect that answer, but I'm relieved somehow.