You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a template specialization is referenced in a way that requires a definition, but the definition of the template appears after the use, the instantiation is never performed.
Examples through the ages:
// C++98:
template struct X { static const int n; };
int k = X::n;
template const int X::n = 5;
// C++11:
template constexpr int f();
int k = f();
template constexpr int f() { return 5; }
// C++14:
template extern const int n;
int k = n;
template const int n = 5;
These are valid, and should cause the instantiation of the relevant template, according to C++14 [temp]/6, which requires the template to "be defined in every translation unit in which it is implicitly instantiated", but doesn't require the definition to precede the use.
The text was updated successfully, but these errors were encountered:
Extended Description
If a template specialization is referenced in a way that requires a definition, but the definition of the template appears after the use, the instantiation is never performed.
Examples through the ages:
// C++98:
template struct X { static const int n; };
int k = X::n;
template const int X::n = 5;
// C++11:
template constexpr int f();
int k = f();
template constexpr int f() { return 5; }
// C++14:
template extern const int n;
int k = n;
template const int n = 5;
These are valid, and should cause the instantiation of the relevant template, according to C++14 [temp]/6, which requires the template to "be defined in every translation unit in which it is implicitly instantiated", but doesn't require the definition to precede the use.
The text was updated successfully, but these errors were encountered: