My question concerns this very simple and short code where an overload resolution is attempted between two non-template functions accepting an array reference parameter. The question has been posted elsewhere, but in a template deduction context. Here's the code:
#include <iostream>
void foo ( const int (&x) [3] ) { std::cout << "3\n"; }
void foo ( const int (&x) [2] ) { std::cout << "2\n"; }
int main()
{
foo({1,2,3});
}
g++ 4.8.3 compiles this code selecting the first function as (I suppose) the ONLY viable, while clang 3.4 doesn't compile it, saying that the call to foo is ambiguous (why?).
Which compiler does the right thing?
clang doesn't compile the code even removing the second overload: it seems that an initializer_list is simply not accepted to initialize an array reference.
Is this buggy?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With