So I tried to compile the code below and it failed (as expected):
1.cpp: In function ‘int foo()’:
1.cpp:3:5: error: ‘some’ was not declared in this scope
some ill-formed code
^
But if I remove this line the compiler compiles it without any errors (also expected as it is unknown whether the T
type has random_name()
method or not).
It seems that diagnostic for templates that are not used (not instantiated) is implementation defined to some extent. But perhaps the standard has some requirements for such cases. For example would it conform to the standard to compile the code below without any errors?
I tried to search for the answer on the site but could not find any related questions.
template <class T>
int foo() {
some ill-formed code
return T::random_name();
}
template <>
int foo<int>() { return 0; }
int main() {
return foo<int>();
}