From 0814268dc8b13e44ef48e87424dfec23add7237e Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Thu, 28 Nov 2024 16:03:16 +0100 Subject: [PATCH 1/2] Use template-parameter and template parameter more consistently Try to use template-parameter only when we refer to a grammar construct, and to 'template parameter' everywhere else. Adopt the same logic to template-argument/template argument. This change might not be exhaustive. The aim is to editorially adopt some of the wording changes made in P2841R5 to ease its review in core. --- source/basic.tex | 4 +- source/declarations.tex | 14 ++-- source/overloading.tex | 6 +- source/templates.tex | 173 +++++++++++++++++++--------------------- 4 files changed, 92 insertions(+), 105 deletions(-) diff --git a/source/basic.tex b/source/basic.tex index c1873fb077..daf25937af 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -2135,8 +2135,8 @@ parameter types and return type. Additionally, if the aforementioned overload set is named with a \grammarterm{template-id}, its associated entities also include -its template \grammarterm{template-argument}{s} and -those associated with its type \grammarterm{template-argument}s. +its template template arguments and +those associated with its type template arguments. \pnum The \term{associated namespaces} for a call are diff --git a/source/declarations.tex b/source/declarations.tex index 7cbe7fb501..c99aa2080f 100644 --- a/source/declarations.tex +++ b/source/declarations.tex @@ -778,7 +778,7 @@ \indextext{class name!\idxcode{typedef}}% A \grammarterm{simple-template-id} is only a \grammarterm{typedef-name} if its \grammarterm{template-name} names -an alias template or a template \grammarterm{template-parameter}. +an alias template or a template template parameter. \begin{note} A \grammarterm{simple-template-id} that names a class template specialization is a \grammarterm{class-name}\iref{class.name}. @@ -1671,8 +1671,8 @@ the specification of the structured binding declaration; \item otherwise, if $E$ is an unparenthesized \grammarterm{id-expression} -naming a non-type \grammarterm{template-parameter}\iref{temp.param}, -\tcode{decltype($E$)} is the type of the \grammarterm{template-parameter} +naming a non-type template parameter\iref{temp.param}, +\tcode{decltype($E$)} is the type of the template parameter after performing any necessary type deduction\iref{dcl.spec.auto,dcl.type.class.deduct}; @@ -4021,7 +4021,7 @@ An abbreviated function template is equivalent to a function template\iref{temp.fct} whose \grammarterm{template-parameter-list} includes -one invented type \grammarterm{template-parameter} +one invented \grammarterm{type-parameter} for each generic parameter type placeholder of the function declaration, in order of appearance. For a \grammarterm{placeholder-type-specifier} of the form \keyword{auto}, @@ -4031,7 +4031,7 @@ \grammarterm{type-constraint} \keyword{auto}, the invented parameter is a \grammarterm{type-parameter} with that \grammarterm{type-constraint}. -The invented type \grammarterm{template-parameter} is +The invented \grammarterm{type-parameter} is a template parameter pack if the corresponding \grammarterm{parameter-declaration} declares a function parameter pack. @@ -4040,7 +4040,7 @@ The adjusted function parameters of an abbreviated function template are derived from the \grammarterm{parameter-declaration-clause} by replacing each occurrence of a placeholder with -the name of the corresponding invented \grammarterm{template-parameter}. +the name of the corresponding invented \grammarterm{type-parameter}. \begin{example} \begin{codeblock} template concept C1 = /* ... */; @@ -4068,7 +4068,7 @@ \pnum An abbreviated function template can have a \grammarterm{template-head}. -The invented \grammarterm{template-parameter}{s} are +The invented \grammarterm{type-parameter}{s} are appended to the \grammarterm{template-parameter-list} after the explicitly declared \grammarterm{template-parameter}{s}. \begin{example} diff --git a/source/overloading.tex b/source/overloading.tex index cf7d80931c..7b37ddbc22 100644 --- a/source/overloading.tex +++ b/source/overloading.tex @@ -3103,8 +3103,7 @@ \item an explicit type conversion\iref{expr.type.conv,expr.static.cast,expr.cast}, or \item -a non-type -\grammarterm{template-parameter}\iref{temp.arg.nontype}. +a non-type template parameter\iref{temp.arg.nontype}. \end{itemize} If the target type contains a placeholder type, placeholder type deduction is performed\iref{dcl.type.auto.deduct}, and @@ -4100,7 +4099,8 @@ A \defnx{string literal operator template}{literal!operator!template string} is a literal operator template whose \grammarterm{template-parameter-list} comprises -a single non-type \grammarterm{template-parameter} of class type. +a single \grammarterm{parameter-declaration} that declares a +non-type template parameter of class type. The declaration of a literal operator template shall have an empty \grammarterm{parameter-declaration-clause} and shall declare either a numeric literal operator template diff --git a/source/templates.tex b/source/templates.tex index d616394cc3..564dba7917 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -289,7 +289,7 @@ \keyword{typename} followed by a \grammarterm{qualified-id} -denotes the type in a non-type +denotes the type in a \begin{footnote} Since template \grammarterm{template-parameter}{s} @@ -310,17 +310,17 @@ int i; template void f(T t) { - T t1 = i; // template-parameters \tcode{T} and \tcode{i} + T t1 = i; // template parameters \tcode{T} and \tcode{i} ::T t2 = ::i; // global namespace members \tcode{T} and \tcode{i} } \end{codeblock} -Here, the template \tcode{f} has a \grammarterm{type-parameter} +Here, the template \tcode{f} has a type template parameter called \tcode{T}, rather than an unnamed non-type -\grammarterm{template-parameter} of class \tcode{T}. +template parameter of class \tcode{T}. \end{example} -A \grammarterm{template-parameter} declaration shall not +A template parameter declaration shall not have a \grammarterm{storage-class-specifier}. -Types shall not be defined in a \grammarterm{template-parameter} +Types shall not be defined in a template parameter declaration. \pnum @@ -389,7 +389,7 @@ \end{example} \pnum -A non-type \grammarterm{template-parameter} +A non-type template parameter shall have one of the following (possibly cv-qualified) types: \begin{itemize} \item a structural type (see below), @@ -420,17 +420,17 @@ \pnum An \grammarterm{id-expression} naming -a non-type \grammarterm{template-parameter} of class type \tcode{T} +a non-type template parameter of class type \tcode{T} denotes a static storage duration object of type \tcode{const T}, known as a \defn{template parameter object}, which is template-argument-equivalent\iref{temp.type} to the corresponding template argument after it has been converted -to the type of the \grammarterm{template-parameter}\iref{temp.arg.nontype}. +to the type of the template parameter\iref{temp.arg.nontype}. No two template parameter objects are template-argument-equivalent. \begin{note} If an \grammarterm{id-expression} names -a non-type non-reference \grammarterm{template-parameter}, +a non-reference non-type template parameter, then it is a prvalue if it has non-class type. Otherwise, if it is of class type \tcode{T}, it is an lvalue and has type \tcode{const T}\iref{expr.prim.id.unqual}. @@ -440,10 +440,10 @@ using X = int; struct A {}; template void f() { - i++; // error: change of \grammarterm{template-parameter} value + i++; // error: change of template parameter value &x; // OK - &i; // error: address of non-reference template-parameter + &i; // error: address of non-reference template parameter &a; // OK int& ri = i; // error: attempt to bind non-const reference to temporary const int& cri = i; // OK, const reference binds to temporary @@ -454,8 +454,7 @@ \pnum \begin{note} -A non-type -\grammarterm{template-parameter} +A non-type template parameter cannot be declared to have type \cv{} \keyword{void}. \begin{example} \begin{codeblock} @@ -466,8 +465,7 @@ \end{note} \pnum -A non-type -\grammarterm{template-parameter} +A non-type template parameter \indextext{array!template parameter of type}% of type ``array of \tcode{T}'' or \indextext{function!template parameter of type}% @@ -498,7 +496,7 @@ a template argument \iref{temp.arg} specified after \tcode{=} in a \grammarterm{template-parameter}. A default template argument may be specified for -any kind of \grammarterm{template-parameter} (type, non-type, template) +any kind of template parameter that is not a template parameter pack\iref{temp.variadic}. A default template argument may be specified in a template declaration. A default template argument shall not be specified in @@ -535,14 +533,15 @@ a default template argument, each subsequent \grammarterm{template-parameter} shall either have a default template argument supplied or -be a template parameter pack. +declare a template parameter pack. If a \grammarterm{template-parameter} of a primary class template, primary variable template, or alias template -is a template parameter pack, +declares a template parameter pack, it shall be the last \grammarterm{template-parameter}. -A template parameter pack of a function template -shall not be followed by another template parameter -unless that template parameter can be deduced from the +If a \grammarterm{template-parameter} of a function template +declares a template parameter pack, it +shall not be followed by another \grammarterm{template-parameter} +unless that template parameter is deducible from the parameter-type-list\iref{dcl.fct} of the function template or has a default argument\iref{temp.deduct}. A template parameter of a deduction guide template\iref{temp.deduct.guide} @@ -561,7 +560,7 @@ \indextext{\idxcode{<}!template and}% \pnum When parsing a default template argument -for a non-type \grammarterm{template-parameter}, +for a non-type template-parameter, the first non-nested \tcode{>} is taken as the end of the \grammarterm{template-parameter-list} rather than a greater-than operator. @@ -606,7 +605,7 @@ is a template parameter pack\iref{temp.variadic}. A template parameter pack that is a \grammarterm{parameter-declaration} whose type contains one or more unexpanded packs is a pack expansion. Similarly, -a template parameter pack that is a \grammarterm{type-parameter} with a +a template parameter pack that is a template template parameter with a \grammarterm{template-parameter-list} containing one or more unexpanded packs is a pack expansion. A type parameter pack with a \grammarterm{type-constraint} that @@ -820,7 +819,7 @@ \item each \grammarterm{template-argument} matches the corresponding - \grammarterm{template-parameter}\iref{temp.arg}, + template parameter \iref{temp.arg}, \item substitution of each template argument into the following @@ -851,7 +850,7 @@ of a \grammarterm{simple-template-id} names a constrained non-function template or -a constrained template \grammarterm{template-parameter}, +a constrained template template parameter, and all \grammarterm{template-argument}{s} in the \grammarterm{simple-template-id} @@ -1000,8 +999,8 @@ \begin{note} Names used in a \grammarterm{template-argument} are subject to access control where they appear. -Because a \grammarterm{template-parameter} is not a class member, -no access control applies. +Because a template parameter is not a class member, +no access control applies where the template parameter is used. \end{note} \begin{example} \begin{codeblock} @@ -1110,14 +1109,12 @@ A \grammarterm{template-argument} followed by an ellipsis is a pack expansion\iref{temp.variadic}. -\rSec2[temp.arg.type]{Template type arguments} +\rSec2[temp.arg.type]{Type Template arguments} \pnum A \grammarterm{template-argument} -for a -\grammarterm{template-parameter} -which is a type +for a type template parameter shall be a \grammarterm{type-id}. @@ -1146,11 +1143,11 @@ A template type argument can be an incomplete type\iref{term.incomplete.type}. \end{note} -\rSec2[temp.arg.nontype]{Template non-type arguments} +\rSec2[temp.arg.nontype]{non-type template arguments} \pnum A template argument $E$ for -a non-type \grammarterm{template-parameter} with declared type \tcode{T} +a non-type template parameter with declared type \tcode{T} shall be such that the invented declaration \begin{codeblock} T x = @$E$@ ; @@ -1165,11 +1162,11 @@ (for a default template argument) an \grammarterm{initializer-clause}. \end{note} If the parameter type thus deduced is not permitted -for a \grammarterm{template-parameter} declaration\iref{temp.param}, +for a template parameter declaration\iref{temp.param}, the program is ill-formed. \pnum -The value of a non-type \grammarterm{template-parameter} $P$ +The value of a non-type template parameter $P$ of (possibly deduced) type \tcode{T} is determined from its template argument $A$ as follows. If \tcode{T} is not a class type and @@ -1213,9 +1210,9 @@ Otherwise, the value of $P$ is that of v. \pnum -For a non-type \grammarterm{template-parameter} of reference or pointer type, +For a non-type template parameter of reference or pointer type, or for each non-static data member of reference or pointer type -in a non-type \grammarterm{template-parameter} of class type or subobject thereof, +in a non-type template parameter of class type or subobject thereof, the reference or pointer value shall not refer or point to (respectively): \begin{itemize} @@ -1289,7 +1286,7 @@ \begin{note} A \grammarterm{string-literal}\iref{lex.string} is not an acceptable \grammarterm{template-argument} -for a \grammarterm{template-parameter} of non-class type. +for a non-type template parameter of non-class type. \begin{example} \begin{codeblock} template class X { @@ -1317,7 +1314,7 @@ is not an acceptable \grammarterm{template-argument} when the corresponding -\grammarterm{template-parameter} +template parameter has reference type. \begin{example} \begin{codeblock} @@ -1343,7 +1340,7 @@ A \grammarterm{template-argument} for a template -\grammarterm{template-parameter} +template parameter shall be the name of a class template or an alias template, expressed as \grammarterm{id-expression}. Only primary templates are considered when matching the template template @@ -1354,9 +1351,7 @@ \pnum Any partial specializations\iref{temp.spec.partial} associated with the primary template are considered when a -specialization based on the template -\grammarterm{template-parameter} -is instantiated. +specialization based on the template template parameter is instantiated. If a specialization is not reachable from the point of instantiation, and it would have been selected had it been reachable, the program is ill-formed, no diagnostic required. @@ -1378,23 +1373,23 @@ \end{example} \pnum -A \grammarterm{template-argument} matches a template -\grammarterm{template-parameter} \tcode{P} when -\tcode{P} is at least as specialized as the \grammarterm{template-argument} \tcode{A}. -In this comparison, if \tcode{P} is unconstrained, -the constraints on \tcode{A} are not considered. +A template \grammarterm{template-argument} \tcode{A} matches a template +template parameter \tcode{P} when +\tcode{P} is at least as specialized as \tcode{A}, ignoring constraints +on \tcode{A} if \tcode{P} is unconstrained. If \tcode{P} contains a template parameter pack, then \tcode{A} also matches \tcode{P} if each of \tcode{A}'s template parameters -matches the corresponding template parameter in the +matches the corresponding template parameter declared in the \grammarterm{template-head} of \tcode{P}. -Two template parameters match if they are of the same kind (type, non-type, template), -for non-type \grammarterm{template-parameter}{s}, their types are -equivalent\iref{temp.over.link}, and for template \grammarterm{template-parameter}{s}, -each of their corresponding \grammarterm{template-parameter}{s} matches, recursively. -When \tcode{P}'s \grammarterm{template-head} contains a template parameter +Two template parameters match if they are of the same kind, +for non-type template parameters, their types are +equivalent\iref{temp.over.link}, and for template template parameters, +each of their corresponding template parameters matches, recursively. +When \tcode{P}'s \grammarterm{template-head} contains a \grammarterm{template-parameter} +that declares a template parameter pack\iref{temp.variadic}, the template parameter pack will match zero or more template -parameters or template parameter packs in the \grammarterm{template-head} of -\tcode{A} with the same type and form as the template parameter pack in \tcode{P} +parameters or template parameter packs declared in the \grammarterm{template-head} of +\tcode{A} with the same type and form as the template parameter pack declared in \tcode{P} (ignoring whether those template parameters are template parameter packs). \begin{example} @@ -1454,7 +1449,7 @@ \end{example} \pnum -A template \grammarterm{template-parameter} \tcode{P} is +A template template parameter \tcode{P} is at least as specialized as a template \grammarterm{template-argument} \tcode{A} if, given the following rewrite to two function templates, the function template corresponding to \tcode{P} @@ -1476,12 +1471,12 @@ whose type is a specialization of \tcode{X} with template arguments corresponding to the template parameters from the respective function template where, -for each template parameter \tcode{PP} +for each \grammarterm{template-parameter} \tcode{PP} in the \grammarterm{template-head} of the function template, -a corresponding template argument \tcode{AA} is formed. +a corresponding \grammarterm{template-argument} \tcode{AA} is formed. If \tcode{PP} declares a template parameter pack, then \tcode{AA} is the pack expansion \tcode{PP...}\iref{temp.variadic}; -otherwise, \tcode{AA} is the \grammarterm{id-expression} \tcode{PP}. +otherwise, \tcode{AA} is an \grammarterm{id-expression} denoting \tcode{PP}. \end{itemize} If the rewrite produces an invalid type, then \tcode{P} is not at least as specialized as \tcode{A}. @@ -4429,7 +4424,7 @@ \indextext{type concept|see{concept, type}}% A \defnx{type concept}{concept!type} is a concept whose prototype parameter -is a type \grammarterm{template-parameter}. +is a type template-parameter. \rSec1[temp.res]{Name resolution} @@ -4782,7 +4777,7 @@ as a \grammarterm{template-name} or a \grammarterm{type-name}. When it is used with a \grammarterm{template-argument-list}, -as a \grammarterm{template-argument} for a template \grammarterm{template-parameter}, +as a \grammarterm{template-argument} for a template template parameter, or as the final identifier in the \grammarterm{elaborated-type-specifier} of a friend class template declaration, it is a \grammarterm{template-name} that refers to the @@ -4876,21 +4871,21 @@ \end{example} \pnum -The name of a \grammarterm{template-parameter} +The name of a template parameter shall not be bound to any following declaration whose locus is contained by the scope -to which the template-parameter belongs. +to which the template parameter belongs. \begin{example} \begin{codeblock} template class Y { - int T; // error: \grammarterm{template-parameter} hidden + int T; // error: template parameter hidden void f() { - char T; // error: \grammarterm{template-parameter} hidden + char T; // error: template parameter hidden } friend void T(); // OK, no name bound }; -template class X; // error: hidden by \grammarterm{template-parameter} +template class X; // error: hidden by template parameter \end{codeblock} \end{example} @@ -5344,7 +5339,7 @@ declared with a dependent type, \item associated by name lookup with -a non-type \grammarterm{template-parameter} +a non-type template parameter declared with a type that contains a placeholder type\iref{dcl.spec.auto}, \item @@ -5600,14 +5595,14 @@ \pnum Furthermore, a non-type \grammarterm{template-argument} -is dependent if the corresponding non-type \grammarterm{template-parameter} +is dependent if the corresponding non-type template parameter is of reference or pointer type and the \grammarterm{template-argument} designates or points to a member of the current instantiation or a member of a dependent type. \pnum -A template \grammarterm{template-parameter} is dependent if -it names a \grammarterm{template-parameter} or +A template template parameter is dependent if +it names a template parameter or its terminal name is dependent. \rSec2[temp.dep.res]{Dependent name resolution} @@ -7196,13 +7191,12 @@ \pnum Template arguments that are present shall be specified in the declaration -order of their corresponding -\grammarterm{template-parameter}{s}. +order of their corresponding template parameters. The template argument list shall not specify more \grammarterm{template-argument}{s} than there are corresponding \grammarterm{template-parameter}{s} -unless one of the \grammarterm{template-parameter}{s} is a template +unless one of the \grammarterm{template-parameter}{s} declares a template parameter pack. \begin{example} \begin{codeblock} @@ -7221,8 +7215,7 @@ \pnum Implicit conversions\iref{conv} will be performed on a function argument to convert it to the type of the corresponding function parameter if -the parameter type contains no -\grammarterm{template-parameter}{s} +the parameter type contains no template parameters that participate in template argument deduction. \begin{note} Template parameters do not participate in template argument deduction if @@ -7679,7 +7672,7 @@ Template argument deduction is done by comparing each function template parameter type (call it \tcode{P}) -that contains \grammarterm{template-parameter}{s} that participate in template argument deduction +that contains template parameters that participate in template argument deduction with the type of the corresponding argument of the call (call it \tcode{A}) as described below. @@ -7926,8 +7919,7 @@ \tcode{A}, the type deduction fails. \begin{note} -If a -\grammarterm{template-parameter} +If a template parameter is not used in any of the function parameters of a function template, or is used only in a non-deduced context, its corresponding \grammarterm{template-argument} @@ -8370,7 +8362,7 @@ A given type \tcode{P} can be composed from a number of other -types, templates, and non-type values: +types, templates, and non-type template argument values: \begin{itemize} \item @@ -8382,7 +8374,7 @@ \item A type that is a specialization of a class template (e.g., \tcode{A}) -includes the types, templates, and non-type values referenced by the +includes the types, templates, and non-type template argument values referenced by the template argument list of the specialization. \item An array type includes the array element type and the value of the @@ -8390,7 +8382,7 @@ \end{itemize} \pnum -In most cases, the types, templates, and non-type values that are used +In most cases, the types, templates, and non-type template argument values that are used to compose \tcode{P} participate in template argument deduction. @@ -8406,7 +8398,7 @@ explicitly specified, template argument deduction fails. \begin{note} Under \ref{temp.deduct.call}, -if \tcode{P} contains no \grammarterm{template-parameter}{s} that appear +if \tcode{P} contains no template parameters that appear in deduced contexts, no deduction is done, so \tcode{P} and \tcode{A} need not have the same form. \end{note} @@ -8909,9 +8901,7 @@ \begin{footnote} Although the \grammarterm{template-argument} -corresponding to a -\grammarterm{template-parameter} -of type +corresponding to a template parameter of type \tcode{bool} can be deduced from an array bound, the resulting value will always be \tcode{true} @@ -8979,8 +8969,7 @@ \pnum The \grammarterm{template-argument} -corresponding to a template -\grammarterm{template-parameter} +corresponding to a template template parameter is deduced from the type of the \grammarterm{template-argument} of a class template specialization used in the argument list of a function call. @@ -9117,8 +9106,7 @@ \pnum \begin{example} Here is an example involving conversions on a function argument involved in -\grammarterm{template-argument} -deduction: +template argument deduction: \begin{codeblock} template struct B { @\commentellip@ }; template struct D : public B { @\commentellip@ }; @@ -9134,8 +9122,7 @@ \pnum \begin{example} Here is an example involving conversions on a function argument not involved in -\grammarterm{template-parameter} -deduction: +template argument deduction: \begin{codeblock} template void f(T*,int); // \#1 template void f(T,char); // \#2 From 9fc22b5a369f2088c37eb1bddac695d751a5b85f Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Sat, 28 Dec 2024 10:30:39 +0100 Subject: [PATCH 2/2] Apply Jens' feedback --- source/templates.tex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/templates.tex b/source/templates.tex index 564dba7917..24ac334e79 100644 --- a/source/templates.tex +++ b/source/templates.tex @@ -318,8 +318,8 @@ called \tcode{T}, rather than an unnamed non-type template parameter of class \tcode{T}. \end{example} -A template parameter declaration shall not -have a \grammarterm{storage-class-specifier}. +A \grammarterm{parameter-declaration} of a \grammarterm{template-parameter} +shall not have a \grammarterm{storage-class-specifier}. Types shall not be defined in a template parameter declaration. @@ -560,7 +560,7 @@ \indextext{\idxcode{<}!template and}% \pnum When parsing a default template argument -for a non-type template-parameter, +for a non-type template parameter, the first non-nested \tcode{>} is taken as the end of the \grammarterm{template-parameter-list} rather than a greater-than operator. @@ -1109,7 +1109,7 @@ A \grammarterm{template-argument} followed by an ellipsis is a pack expansion\iref{temp.variadic}. -\rSec2[temp.arg.type]{Type Template arguments} +\rSec2[temp.arg.type]{Type template arguments} \pnum A @@ -1143,7 +1143,7 @@ A template type argument can be an incomplete type\iref{term.incomplete.type}. \end{note} -\rSec2[temp.arg.nontype]{non-type template arguments} +\rSec2[temp.arg.nontype]{Non-type template arguments} \pnum A template argument $E$ for @@ -4424,7 +4424,7 @@ \indextext{type concept|see{concept, type}}% A \defnx{type concept}{concept!type} is a concept whose prototype parameter -is a type template-parameter. +is a type template parameter. \rSec1[temp.res]{Name resolution}