Consider the following code:
#include <iostream>
#include <cinttypes>
template<class T>
void f();
template<>
inline void f<long long>() {
std::cout<<"f<long long>()"<<std::endl;
}
int main(int , char** ) {
std::cout<<"sizeof(long)="<<sizeof(long)<<std::endl;
std::cout<<"sizeof(long long)="<<sizeof(long long)<<std::endl;
f<int64_t>();
return 0;
}
32-bit G++ 4.6.3 compiles this successfully and produces the output:
sizeof(long)=4
sizeof(long long)=8
f<long long>()
Compiling under 64-bit G++ 4.6.3 however produces the linker error:
undefined reference to `void f<long>()'
ld returned 1 exit status
even though compiling and running with the f<int64_t>()
line commented out produces:
sizeof(long)=8
sizeof(long long)=8
Is there a good reason why 64-bit G++ treats f<long>
and f<long long>
as different functions, even though long
and long long
are the same size, or is this a bug that I should report?