3

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;
}

Edit It seems that sizeof(long long) is 8 bytes both for clang (64bit linux build) and VS2015 (64bit windows build). So clang should select int64_t overload, no?

Edit 2 I think I understand now. The int64_t is long for clang and long long for vs2015. That's why the difference in compilation.

0kcats
  • 672
  • 5
  • 16
  • You should check this http://stackoverflow.com/questions/10579544/ambiguous-overload-of-functions-like-msglong-with-candidates-msgint32-t and the issue opened/closed to clang https://llvm.org/bugs/show_bug.cgi?id=23404 – Jans Aug 25 '16 at 21:08
  • I found this link to be more helpful to my question http://stackoverflow.com/questions/4160945/c-long-long-int-vs-long-int-vs-int64-t – 0kcats Aug 26 '16 at 08:17

0 Answers0