|
4889 | 4889 |
|
4890 | 4890 | \pnum
|
4891 | 4891 | If the explicit instantiation is for a class or member class, the
|
4892 |
| -\grammarterm{elaborated-type-specifier} in the \grammarterm{declaration} shall |
4893 |
| -include a \grammarterm{simple-template-id}. If the explicit instantiation is for |
| 4892 | +\grammarterm{elaborated-type-specifier} in the \grammarterm{declaration} |
| 4893 | +shall include a \grammarterm{simple-template-id}; |
| 4894 | +otherwise, the \grammarterm{declaration} |
| 4895 | +shall be a \grammarterm{simple-declaration} whose \grammarterm{init-declarator-list} |
| 4896 | +comprises a single \grammarterm{init-declarator} |
| 4897 | +that does not have an \grammarterm{initializer}. |
| 4898 | +If the explicit instantiation is for |
4894 | 4899 | a function or member function,
|
4895 | 4900 | the
|
4896 | 4901 | \grammarterm{unqualified-id}
|
4897 | 4902 | in the
|
4898 |
| -\grammarterm{declaration} |
| 4903 | +\grammarterm{declarator} |
4899 | 4904 | shall be either a
|
4900 | 4905 | \grammarterm{template-id}
|
4901 | 4906 | or, where all template arguments can be deduced, a
|
|
4915 | 4920 | the name of the class template specialization in the
|
4916 | 4921 | \grammarterm{qualified-id}
|
4917 | 4922 | for the member name shall be a \grammarterm{simple-template-id}.
|
4918 |
| -If the explicit instantiation is for a variable, the |
4919 |
| -\grammarterm{unqualified-id} in the declaration shall be a |
4920 |
| -\grammarterm{template-id}. |
| 4923 | +If the explicit instantiation is for a variable template specialization, |
| 4924 | +the \grammarterm{unqualified-id} in the \grammarterm{declarator} |
| 4925 | +shall be a \grammarterm{simple-template-id}. |
4921 | 4926 | An explicit instantiation shall appear in an enclosing namespace
|
4922 | 4927 | of its template. If the name declared in the explicit
|
4923 | 4928 | instantiation is an unqualified name, the explicit instantiation
|
|
4958 | 4963 | of the explicit instantiation names an implicitly-declared special member
|
4959 | 4964 | function (Clause~\ref{special}), the program is ill-formed.
|
4960 | 4965 |
|
| 4966 | +\pnum |
| 4967 | +The \grammarterm{declaration} in an \grammarterm{explicit-instantiation} and the \grammarterm{declaration} produced by the corresponding substitution into the templated function, variable, or class are two declarations of the same entity. |
| 4968 | +\begin{note} |
| 4969 | +These declarations are required to have matching types as specified in~\ref{basic.link}, except as specified in~\ref{except.spec}. |
| 4970 | +\begin{example} |
| 4971 | +\begin{codeblock} |
| 4972 | +template<typename T> T var = {}; |
| 4973 | +template float var<float>; // OK, instantiated variable has type \tcode{float} |
| 4974 | +template int var<int[16]>[]; // OK, absence of major array bound is permitted |
| 4975 | +template int *var<int>; // error: instantiated variable has type \tcode{int} |
| 4976 | + |
| 4977 | +template<typename T> auto av = T(); |
| 4978 | +template int av<int>; // OK, variable with type \tcode{int} can be redeclared with type \tcode{auto} |
| 4979 | + |
| 4980 | +template<typename T> auto f() {} |
| 4981 | +template void f<int>(); // error: function with deduced return type |
| 4982 | + // redeclared with non-deduced return type~(\ref{dcl.spec.auto}) |
| 4983 | +\end{codeblock} |
| 4984 | +\end{example} |
| 4985 | +\end{note} |
| 4986 | +Despite its syntactic form, the \grammarterm{declaration} in an \grammarterm{explicit-instantiation} for a variable is not itself a definition and does not conflict with the definition instantiated by an explicit instantiation definition for that variable. |
| 4987 | + |
4961 | 4988 | \pnum
|
4962 | 4989 | For a given set of template arguments, if an explicit
|
4963 | 4990 | instantiation of a template appears after a declaration of
|
|
5033 | 5060 | literal types,
|
5034 | 5061 | variables of reference types, and class template specializations,
|
5035 | 5062 | explicit instantiation declarations have the
|
5036 |
| -effect of suppressing the implicit instantiation of the entity to which they |
5037 |
| -refer. \begin{note} The intent is that an inline function that is the |
| 5063 | +effect of suppressing the implicit instantiation |
| 5064 | +of the definition of the entity to which they refer. |
| 5065 | +\begin{note} The intent is that an inline function that is the |
5038 | 5066 | subject of an explicit instantiation declaration will still be implicitly
|
5039 | 5067 | instantiated when odr-used~(\ref{basic.def.odr}) so that the body can be considered for inlining, but
|
5040 | 5068 | that no out-of-line copy of the inline function would be generated in the
|
|
0 commit comments