Consider the code below:
#include <iostream>
class Test {
public:
Test() {std::cout << "I am called\n";};
template <typename T>
Test(T t);
};
template <typename T> Test::Test(T t){ std::cout << t << "\n";};
// Explicit template instantiation
template Test::Test<int>(int);
template Test::Test<double>(double);
int main() {
Test test;
Test test2(12342);
Test test3(3.1415);
return 0;
}
This code compiles and works fine with GCC (my version is 13.2). Output is as I expect:
I am called
12342
3.1415
Clang (my version is 16.0.0) throws an error and the code does not compile:
<source>:14:16: error: qualified reference to 'Test' is a constructor name rather than a type in this context
template Test::Test<int>(int);
^
<source>:14:20: error: expected unqualified-id
template Test::Test<int>(int);
^
<source>:15:16: error: qualified reference to 'Test' is a constructor name rather than a type in this context
template Test::Test<double>(double);
^
<source>:15:20: error: expected unqualified-id
template Test::Test<double>(double);
^
4 errors generated.
Can anyone help me understand the problem or direct me to a source?