jeudi 25 août 2016

Overloaded function with int64_t parameter and LL integral constant argument

I've read here a few times that a correct way to specify an integer constant for int64_t type is to use LL suffix. When I pass an LL constant to an overloaded function that has int64_t and int32_t versions I hope the compiler to select int64_t variant of the function. Why the following code errors with "call to 'fun' is ambiguous" in clang++ 3.8.0. It would compile if I cast the constant to int64_t explicitly. Is this a compiler bug or a language feature? (It compiles in vs2015)

char fun(int32_t i)
{
  return (char)i;
}
char fun(int64_t i)
{
  return (char)i;
}
int main()
{
  fun(0x100LL);//<<<ERROR?.
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire