The C++ Language Standard states the following concerning template components in the Standard Library:
The effects are undefined…if an incomplete type is used as a template argument when instantiating a template component, unless specifically allowed for that component (C++11 §17.6.4.8/2).
Does the following cause instantiation of the std::vector class template?
class X;
std::vector<X> f(); // Declaration only; we will define it when X is complete
To ask it another way, in the function declaration std::vector<X> f();, is std::vector instantiated with the argument X? Or, is std::vector<X> not instantiated until f() is odr-used or defined?
Likewise, does the following cause instantiation of the std::vector class template?
class X;
typedef std::vector<X> XVector; // We will complete X before we use XVector
While I use std::vector in these examples, the question applies equally to all templates.
§ 14.7.1\1 Implicit instantiation [temp.inst]
§ 8.3.5\9 Functions [dcl.fct]
§ 3.1\2 Declarations and definitions [basic.def]
It’s only instantiated if it’s required. I couldn’t find a clear definition anywhere, but the second quote says that those declaratations are not definitions, which seems to be the same to me.