|
2680 | 2680 | which shall be a class or variable template. |
2681 | 2681 |
|
2682 | 2682 | \pnum |
| 2683 | +A \defnadj{separately instantiated}{construct} |
| 2684 | +of a templated function \tcode{F} is a |
| 2685 | +\begin{itemize} |
| 2686 | +\item default argument, |
| 2687 | +\item \grammarterm{noexcept-specifier}, or |
| 2688 | +\item \grammarterm{function-contract-specifier} |
| 2689 | +\end{itemize} |
| 2690 | +of \tcode{F}. |
2683 | 2691 | For purposes of name lookup and instantiation, |
2684 | | -default arguments, |
2685 | | -\grammarterm{type-constraint}{s}, |
2686 | | -\grammarterm{requires-clause}{s}\iref{temp.pre}, |
2687 | | -and |
2688 | | -\grammarterm{noexcept-specifier}{s} |
2689 | | -of function templates |
2690 | | -and |
2691 | | -of member functions of class templates |
| 2692 | +separately instantiated constructs, |
| 2693 | +\grammarterm{type-constraint}{s}, and |
| 2694 | +\grammarterm{requires-clause}{s}\iref{temp.pre} |
2692 | 2695 | are considered definitions; |
2693 | 2696 | each |
2694 | | -default argument, |
2695 | | -\grammarterm{type-constraint}, |
2696 | | -\grammarterm{requires-clause}, |
2697 | | -or |
2698 | | -\grammarterm{noexcept-specifier} |
| 2697 | +separately instantiated construct, |
| 2698 | +\grammarterm{type-constraint}, or |
| 2699 | +\grammarterm{requires-clause} |
2699 | 2700 | is a separate definition |
2700 | 2701 | which is unrelated |
2701 | 2702 | to the templated function definition or |
2702 | 2703 | to any other |
2703 | | -default arguments, |
2704 | | -\grammarterm{type-constraint}{s}, |
2705 | | -\grammarterm{requires-clause}{s}, |
2706 | | -or |
2707 | | -\grammarterm{noexcept-specifier}{s}. |
| 2704 | +separately instantiated constructs, |
| 2705 | +\grammarterm{type-constraint}{s}, or |
| 2706 | +\grammarterm{requires-clause}{s}. |
2708 | 2707 | For the purpose of instantiation, the substatements of a constexpr if |
2709 | 2708 | statement\iref{stmt.if} are considered definitions. |
2710 | 2709 | For the purpose of name lookup and instantiation, |
|
6649 | 6648 | X<char> ch; // error: incomplete type \tcode{X<char>} |
6650 | 6649 | \end{codeblock} |
6651 | 6650 | \end{example} |
6652 | | -\begin{note} |
6653 | | -Within a template declaration, |
6654 | | -a local class\iref{class.local} or enumeration and the members of |
6655 | | -a local class are never considered to be entities that can be separately |
6656 | | -instantiated (this includes their default arguments, |
6657 | | -\grammarterm{noexcept-specifier}{s}, and non-static data member |
6658 | | -initializers, if any, |
6659 | | -but not their \grammarterm{type-constraint}{s} or \grammarterm{requires-clause}{s}). |
6660 | | -As a result, the dependent names are looked up, the |
6661 | | -semantic constraints are checked, and any templates used are instantiated as |
6662 | | -part of the instantiation of the entity within which the local class or |
6663 | | -enumeration is declared. |
6664 | | -\end{note} |
6665 | 6651 |
|
6666 | 6652 | \pnum |
6667 | 6653 | The implicit instantiation of a class template specialization causes |
|
6681 | 6667 | unscoped member enumerations, and |
6682 | 6668 | member anonymous unions. |
6683 | 6669 | \end{itemize} |
6684 | | -The implicit instantiation of a class template specialization |
6685 | | -does not cause the implicit instantiation of |
6686 | | -default arguments or \grammarterm{noexcept-specifier}{s} |
6687 | | -of the class member functions. |
6688 | 6670 | \begin{example} |
6689 | 6671 | \begin{codeblock} |
6690 | 6672 | template<class T> |
|
6748 | 6730 | implicitly instantiated when it is referenced in a context that |
6749 | 6731 | requires a function definition to exist or |
6750 | 6732 | if the existence of the definition affects the semantics of the program. |
6751 | | -Unless a call is to a function template explicit specialization or |
6752 | | -to a member function of an explicitly specialized class template, |
6753 | | -a default argument for a function template or a member function of a |
6754 | | -class template is implicitly instantiated when the function is |
6755 | | -called in a context that requires the value of the default argument. |
6756 | 6733 | \begin{note} |
6757 | 6734 | An inline function |
6758 | 6735 | that is the subject of an explicit instantiation declaration |
|
6883 | 6860 | causes specializations in the default member initializer to be instantiated. |
6884 | 6861 |
|
6885 | 6862 | \pnum |
6886 | | -If a templated function |
| 6863 | +The separately instantiated constructs\iref{temp.decls.general} |
| 6864 | +of a templated function \tcode{F} that is either |
| 6865 | +\begin{itemize} |
| 6866 | +\item |
| 6867 | +a member of a local class or |
| 6868 | +\item |
| 6869 | +the function call operator of the closure type |
| 6870 | +of a non-generic lambda-expression |
| 6871 | +\end{itemize} |
| 6872 | +are instantiated when the declaration of \tcode{F} is instantiated. |
| 6873 | +\begin{note} |
| 6874 | +For the purposes of instantiation, |
| 6875 | +these constructs are still considered separately |
| 6876 | +from the function to which they belong. |
| 6877 | +\end{note} |
| 6878 | + |
| 6879 | +\pnum |
| 6880 | +Other than as specified above, |
| 6881 | +when a templated function |
6887 | 6882 | \tcode{f} |
6888 | 6883 | is called in a way that requires a default argument to be used, |
6889 | 6884 | the dependent names are looked up, the semantics constraints are checked, |
|
6902 | 6897 | \tcode{f}. |
6903 | 6898 |
|
6904 | 6899 | \pnum |
| 6900 | +\begin{note} |
6905 | 6901 | Each default argument is instantiated independently. |
| 6902 | +\end{note} |
6906 | 6903 | \begin{example} |
6907 | 6904 | \begin{codeblock} |
6908 | 6905 | template<class T> void f(T x, T y = ydef(T()), T z = zdef(T())); |
|
6920 | 6917 | \end{example} |
6921 | 6918 |
|
6922 | 6919 | \pnum |
6923 | | -The \grammarterm{noexcept-specifier} and \grammarterm{function-contract-specifier}s |
6924 | | -of a function template specialization |
6925 | | -are not instantiated along with the function declaration; |
6926 | | -they are instantiated |
6927 | | -when needed\iref{except.spec,dcl.contract.func}. If such a |
6928 | | -specifier is needed but has not yet been |
6929 | | -instantiated, the dependent names are looked up, the semantics constraints are |
6930 | | -checked, and the instantiation of any template used in the |
6931 | | -specifier is done as if it were being done as part |
6932 | | -of instantiating the declaration of the specialization at that point. |
| 6920 | +Other than as specified above, |
| 6921 | +the separately instantiated constructs |
| 6922 | +of a specialization of a templated function |
| 6923 | +are instantiated only when needed\iref{except.spec,dcl.contract.func}. |
| 6924 | +When such a construct is instantiated, |
| 6925 | +the dependent names are looked up, |
| 6926 | +the semantics constraints are checked, and |
| 6927 | +the instantiation of any template used in the construct |
| 6928 | +is done as if it were being done as part of instantiating the declaration |
| 6929 | +of the specialization at that point. |
6933 | 6930 |
|
6934 | 6931 | \pnum |
6935 | 6932 | \begin{note} |
|
8053 | 8050 | \end{note} |
8054 | 8051 | Invalid types and expressions can result in a deduction failure |
8055 | 8052 | only in the immediate context of the deduction substitution loci. |
| 8053 | +The \defnadj{immediate}{context} of a deduction substitution locus |
| 8054 | +is that deduction substitution locus, |
| 8055 | +excluding bodies of \grammarterm{lambda-expression}s and separately instantiated constructs. |
| 8056 | +\begin{example} |
| 8057 | +\begin{codeblock} |
| 8058 | +template<typename T> |
| 8059 | +T* fun(T&& v); // \#1: the deduction substitution locus is the function type |
| 8060 | + // ``function of (rvalue reference to \tcode{T}) returning pointer to \tcode{T}'' |
| 8061 | + |
| 8062 | +void fun(...); // \#2 |
| 8063 | + |
| 8064 | +void test() |
| 8065 | +{ |
| 8066 | + int i; |
| 8067 | + fun(i); // selects \#2 (forming the type ``pointer to reference to \tcode{int}'' fails in \#1) |
| 8068 | +} |
| 8069 | +\end{codeblock} |
| 8070 | +\end{example} |
| 8071 | +\begin{note} |
| 8072 | +Separately instantiated constructs are excluded from the immediate contexts |
| 8073 | +even if they are instantiated at the same time. |
| 8074 | +\end{note} |
8056 | 8075 | \begin{note} |
8057 | 8076 | The substitution into types and expressions can result |
8058 | | -in effects such as the instantiation of class template specializations and/or |
8059 | | -function template specializations, the generation of implicitly-defined functions, |
8060 | | -etc. Such effects are not in the ``immediate context'' and can result in the |
8061 | | -program being ill-formed. |
| 8077 | +in effects such as the instantiation of template specializations, |
| 8078 | +the generation of implicitly-defined functions, etc. |
| 8079 | +Such effects are not in the immediate context |
| 8080 | +and can result in the program being ill-formed. |
8062 | 8081 | \end{note} |
8063 | 8082 |
|
8064 | 8083 | \pnum |
8065 | | -When substituting into a \grammarterm{lambda-expression}, |
8066 | | -substitution into its body is not in the immediate context. |
8067 | 8084 | \begin{note} |
8068 | | -The intent is to avoid requiring implementations to deal with |
8069 | | -substitution failure involving arbitrary statements. |
| 8085 | +No \grammarterm{statement} is ever in the immediate context |
| 8086 | +of a deduction substitution locus. |
8070 | 8087 | \begin{example} |
8071 | 8088 | \begin{codeblock} |
8072 | 8089 | template <class T> |
|
0 commit comments