From b8da0334ed9bbe3725ee589144322b95c01ff535 Mon Sep 17 00:00:00 2001 From: Eisenwave Date: Thu, 10 Jul 2025 19:07:12 +0200 Subject: [PATCH 1/2] P3096R12 Function Parameter Reflection in Reflection for C++26 --- source/basic.tex | 1 + source/meta.tex | 199 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 197 insertions(+), 3 deletions(-) diff --git a/source/basic.tex b/source/basic.tex index 26aa0f32df..3345fa85b4 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -5611,6 +5611,7 @@ \item a variable\iref{basic.pre}, \item a structured binding\iref{dcl.struct.bind}, \item a function\iref{dcl.fct}, +\item a function parameter\iref{dcl.fct}, \item an enumerator\iref{dcl.enum}, \item an annotation\iref{dcl.attr.grammar}, \item a type alias\iref{dcl.typedef}, diff --git a/source/meta.tex b/source/meta.tex index 5bbf10c670..77ccd1bbef 100644 --- a/source/meta.tex +++ b/source/meta.tex @@ -2683,6 +2683,11 @@ consteval bool is_move_assignment(info r); consteval bool is_destructor(info r); + consteval bool is_function_parameter(info r); + consteval bool is_explicit_object_parameter(info r); + consteval bool has_default_argument(info r); + consteval bool has_ellipsis_parameter(info r); + consteval bool is_template(info r); consteval bool is_function_template(info r); consteval bool is_variable_template(info r); @@ -2715,6 +2720,9 @@ consteval bool has_template_arguments(info r); consteval info template_of(info r); consteval vector template_arguments_of(info r); + consteval vector parameters_of(info r); + consteval info variable_of(info r); + consteval info return_type_of(info r); // \ref{meta.reflection.access.context}, access control context struct access_context; @@ -3238,6 +3246,47 @@ operator function template, or conversion function template. Otherwise, \tcode{false}. +\item + Otherwise, if \tcode{r} represents the $i^\text{th}$ parameter of a function $F$ + that is an (implicit or explicit) specialization of a templated function $T$ + and the $i^\text{th}$ parameter of the instantiated declaration of $T$ + whose template arguments are those of $F$ would be instantiated from a pack, + then \tcode{false}. +\item + Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$, + then let $S$ be the set of declarations, + ignoring any explicit instantiations, + that precede some point in the evaluation context + and that declare either $F$ or a templated function + of which $F$ is a specialization; + \tcode{true} if + \begin{itemize} + \item + there is a declaration $D$ in $S$ that introduces a name $N$ for either $P$ + or the parameter corresponding to $P$ + in the templated function that $D$ declares and + \item + no declaration in $S$ does so using any name other than $N$. + \end{itemize} + Otherwise, \tcode{false}. + \begin{example} +\begin{codeblock} +void fun(int); +constexpr std::meta::info r = parameters_of(^^fun)[0]; +static_assert(!has_identifier(r)); + +void fun(int x); +static_assert(has_identifier(r)); + +void fun(int x); +static_assert(has_identifier(r)); + +void poison() { + void fun(int y); +} +static_assert(!has_identifier(r)); +\end{codeblock} + \end{example} \item Otherwise, if \tcode{r} represents a variable, then \tcode{false} if the declaration of that variable @@ -3298,6 +3347,15 @@ \item Otherwise, if \tcode{r} represents a literal operator or literal operator template, then the \grammarterm{ud-suffix} of the operator or operator template. +\item + Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$, + then let $S$ be the set of declarations, + ignoring any explicit instantiations, + that precede some point in the evaluation context + and that declare either $F$ + or a templated function of which $F$ is a specialization; + the name that was introduced by a declaration in $S$ + for the parameter corresponding to $P$. \item Otherwise, if \tcode{r} represents an entity, then the identifier introduced by the declaration of that entity. @@ -3378,8 +3436,9 @@ enumerator, non-static data member, unnamed bit-field, -direct base class relationship, or -data member description. +direct base class relationship, +data member description, or +function parameter. Otherwise, \tcode{false}. \end{itemdescr} @@ -3397,7 +3456,11 @@ \returns \begin{itemize} \item - If \tcode{r} represents a + If \tcode{r} represents the $i^\text{th}$ parameter of a function $F$, + then the $i^\text{th}$ type + in the parameter-type-list of $F$\iref{dcl.fct}. +\item + Otherwise, if \tcode{r} represents a value, object, variable, @@ -3968,6 +4031,70 @@ Otherwise, \tcode{false}. \end{itemdescr} +\indexlibraryglobal{is_function_parameter}% +\begin{itemdecl} +consteval bool is_function_parameter(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\tcode{true} if \tcode{r} represents a function parameter. +Otherwise, \tcode{false}. +\end{itemdescr} + +\indexlibraryglobal{is_explicit_object_parameter}% +\begin{itemdecl} +consteval bool is_explicit_object_parameter(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\tcode{true} if \tcode{r} represents a function parameter +that is an explicit object parameter\iref{dcl.fct}. +Otherwise, \tcode{false}. +\end{itemdescr} + +\indexlibraryglobal{has_default_argument}% +\begin{itemdecl} +consteval bool has_default_argument(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +If \tcode{r} represenst a parameter $P$ of a function $F$, then: +\begin{itemize} +\item + If $F$ is a specialization of a templated function $T$, + then \tcode{true} if there exists a declaration $D$ of $T$ + that precedes some point in the evaluation context + and $D$ specifies a default argument + for the parameter of $T$ corresponding to $P$. + Otherwise, \tcode{false}. +\item + Otherwise, if there exists a declaration $D$ of $F$ + that precedes some point in the evaluation context + and $D$ specifies a default argument for $P$, + then \tcode{true}. +\end{itemize} +Otherwise, \tcode{false}. +\end{itemdescr} + +\indexlibraryglobal{has_ellipsis_parameter}% +\begin{itemdecl} +consteval bool has_ellipsis_parameter(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\tcode{true} if \tcode{r} represents a function type +that has an ellipsis in its parameter-type-list\iref{dcl.fct}. +Otherwise, \tcode{false}. +\end{itemdescr} + \indexlibraryglobal{is_template}% \begin{itemdecl} consteval bool is_template(info r); @@ -4325,6 +4452,72 @@ \end{example} \end{itemdescr} +\indexlibraryglobal{parameters_of}% +\begin{itemdecl} +consteval vector parameters_of(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constantwhen +\tcode{r} represents a function or a function type. + +\pnum +\returns +\begin{itemize} +\item + If \tcode{r} represents a function $F$, + then a \tcode{vector} containing reflections of the parameters of $F$, + in the order they appear in a declaration of $F$. +\item + Otherwise, \tcode{r} represents a function type $T$; + a \tcode{vector} containing reflections of the types + in parameter-type-list\iref{dcl.fct} of $T$, + in the order they appear in the parameter-type-list. +\end{itemize} +\end{itemdescr} + +\indexlibraryglobal{variable_of}% +\begin{itemdecl} +consteval info variable_of(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constantwhen +\begin{itemize} +\item + \tcode{r} represents a parameter of a function $F$ and +\item + there is a point $P$ in the evaluation context + for which the innermost non-block scope enclosing $P$ + is the function parameter scope\iref{basic.scope.param} + associated with $F$. +\end{itemize} + +\pnum +\returns +The reflection of the parameter variable corresponding to \tcode{r}. +\end{itemdescr} + +\indexlibraryglobal{return_type_of}% +\begin{itemdecl} +consteval info return_type_of(info r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constantwhen +Either \tcode{r} represents a function +and \tcode{\exposid{has-type}(r)} is \tcode{true} +or \tcode{r} represents a function type. + +\pnum +\returns +The reflection of the return type +of the function or function type represented by \tcode{r}. +\end{itemdescr} + \rSec2[meta.reflection.access.context]{Access control context} \pnum From 38c2a206423dfa3f35d8ee46e662f7bdfa60ac1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Mon, 14 Jul 2025 23:00:05 +0100 Subject: [PATCH 2/2] [meta.reflection.queries] Add missing "in [which]"s --- source/meta.tex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/meta.tex b/source/meta.tex index 77ccd1bbef..880f84f533 100644 --- a/source/meta.tex +++ b/source/meta.tex @@ -4393,7 +4393,7 @@ A \tcode{vector} containing reflections of the template arguments of the template specialization represented by \tcode{r}, -in the order they appear in the corresponding template argument list. +in the order in which they appear in the corresponding template argument list. For a given template argument $A$, its corresponding reflection $R$ is determined as follows: \begin{itemize} @@ -4468,12 +4468,12 @@ \item If \tcode{r} represents a function $F$, then a \tcode{vector} containing reflections of the parameters of $F$, - in the order they appear in a declaration of $F$. + in the order in which they appear in a declaration of $F$. \item Otherwise, \tcode{r} represents a function type $T$; a \tcode{vector} containing reflections of the types in parameter-type-list\iref{dcl.fct} of $T$, - in the order they appear in the parameter-type-list. + in the order in which they appear in the parameter-type-list. \end{itemize} \end{itemdescr}