When a function template is implicitly instantiated, is the declaration or the definition of the template required?
It seems that compilers only require a declaration:
template <typename T>
T f();
int g() {
// Compiles OK, even though f's definition is not available here.
return f<int>();
}
template <typename T>
T f() {
return 123;
}
int main()
{
std::cout << g();
}
I'm struggling to see where this behavior is specified in the Standard. Could anyone help finding that?
For example, doesn't the "temp.point" clause say that the point of f's instantiation should immediately follow g's definition, which should lead to compilation error as the f is not defined yet?
<...> the point of instantiation for such a specialization immediately follows the namespace scope declaration or definition that refers to the specialization.