Tool/software: TI C/C++ Compiler
Hello
Today I ran into a problem with the 8.3 compiler series (I did not try any earlier compilers as I make use of C++14 features).
Here's some code that demonstrates the problem:
template<typename T> using AlwaysVoid = void;
template<typename T> T val() { return T(); }
template<typename T> T* ptr() { static const T t; return &t; }
template<typename T> T& ref() { return *ptr<T>(); }
template<typename T> int f1(T&& t, char(*)[sizeof(T)]) { return 0; }
int g1a() // won't compile
{
return sizeof( f1(val<int>(), 0) );
}
int g1b() // compiles
{
using type = char(*)[sizeof(int)];
return sizeof( f1(val<int>(), (type) 0) );
}
template<typename T> int f2(T&& t, AlwaysVoid<T>*) { return 0; }
int g2a() // compiles
{
return sizeof( f2(val<int>(), 0) );
}
template<typename T> int f3(T& t, char(*)[sizeof(T)]) { return 0; }
int g3a() // won't compile
{
return sizeof( f3(ref<int>(), 0) );
}
int g3b() // compiles
{
using type = char(*)[sizeof(int)];
return sizeof( f3(ref<int>(), (type) 0) );
}
template<typename T> int f4(T& t, AlwaysVoid<T>*) { return 0; }
int g4a() // compiles
{
return sizeof( f4(ref<int>(), 0) );
}
Trying to compile that file I get
C:\Temp>C:\ti\ti-cgt-c6000_8.3.4\bin\cl6x.exe -s t.cxx --verbose_diagnostics
"t.cxx", line 10: error: no instance of function template "f1" matches the
argument list
argument types are: (int, int)
return sizeof( f1(val<int>(), 0) );
^
"t.cxx", line 30: error: no instance of function template "f3" matches the
argument list
argument types are: (int, int)
return sizeof( f3(ref<int>(), 0) );
^
2 errors detected in the compilation of "t.cxx".
>> Compilation failure
Most other tested compiler (GCC, Clang, MSVC) accept the code. Curiously, the Intel Compiler also rejects it but my interpretation of the C++14 standard is that it is legal C++.
Notice that adding explicit casts helps, which makes me believe that the compiler tries to perform argument deduction on the second parameter.
Kind regards
Markus