Juha Nieminen
2015-05-04 08:00:52 UTC
Consider this program:
//--------------------------------------------------------------------
#include <cstdint>
#include <iostream>
void foo(std::int32_t) { std::cout << "int32_t\n"; }
void foo(std::int64_t) { std::cout << "int64_t\n"; }
int main() { foo(123L); }
//--------------------------------------------------------------------
If I try to compile it with clang++ (in C++11 mode), on a 64-bit target
it gives me:
test.cc:8:14: error: call to 'foo' is ambiguous
I do not understand why exactly it's doing that. Why would it be
ambiguous? (Given that a long type is 64-bit on this target, it would
quite unambiguously not fit into a std::int32_t, so why does it
consider it a valid match?) Note that if I call foo(123) it does not
give any error.
The problem can be solved by adding this version:
void foo(long) { std::cout << "long\n"; }
The thing is, I don't believe this to be portable anymore. If for
example std::int64_t happens to be defined as 'long' in some other
compiler, it would give an error. Indeed, if I did this:
void foo(long long) { std::cout << "long long\n"; }
it gives me:
test.cc:7:6: error: redefinition of 'foo'
And yes, I need to use std::int32_t & co because this is rather low-level
binary code manipulation which needs to handle exact bit sizes.
--- news://freenews.netfront.net/ - complaints: ***@netfront.net ---
//--------------------------------------------------------------------
#include <cstdint>
#include <iostream>
void foo(std::int32_t) { std::cout << "int32_t\n"; }
void foo(std::int64_t) { std::cout << "int64_t\n"; }
int main() { foo(123L); }
//--------------------------------------------------------------------
If I try to compile it with clang++ (in C++11 mode), on a 64-bit target
it gives me:
test.cc:8:14: error: call to 'foo' is ambiguous
I do not understand why exactly it's doing that. Why would it be
ambiguous? (Given that a long type is 64-bit on this target, it would
quite unambiguously not fit into a std::int32_t, so why does it
consider it a valid match?) Note that if I call foo(123) it does not
give any error.
The problem can be solved by adding this version:
void foo(long) { std::cout << "long\n"; }
The thing is, I don't believe this to be portable anymore. If for
example std::int64_t happens to be defined as 'long' in some other
compiler, it would give an error. Indeed, if I did this:
void foo(long long) { std::cout << "long long\n"; }
it gives me:
test.cc:7:6: error: redefinition of 'foo'
And yes, I need to use std::int32_t & co because this is rather low-level
binary code manipulation which needs to handle exact bit sizes.
--- news://freenews.netfront.net/ - complaints: ***@netfront.net ---