Skip to content

Commit 729d34b

Browse files
authored
Merge 2025-06 CWG Motion 9
P3096R12 Function Parameter Reflection in Reflection for C++26
2 parents d9bbb54 + 38c2a20 commit 729d34b

File tree

2 files changed

+198
-4
lines changed

2 files changed

+198
-4
lines changed

source/basic.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5611,6 +5611,7 @@
56115611
\item a variable\iref{basic.pre},
56125612
\item a structured binding\iref{dcl.struct.bind},
56135613
\item a function\iref{dcl.fct},
5614+
\item a function parameter\iref{dcl.fct},
56145615
\item an enumerator\iref{dcl.enum},
56155616
\item an annotation\iref{dcl.attr.grammar},
56165617
\item a type alias\iref{dcl.typedef},

source/meta.tex

Lines changed: 197 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,11 @@
26832683
consteval bool is_move_assignment(info r);
26842684
consteval bool is_destructor(info r);
26852685

2686+
consteval bool is_function_parameter(info r);
2687+
consteval bool is_explicit_object_parameter(info r);
2688+
consteval bool has_default_argument(info r);
2689+
consteval bool has_ellipsis_parameter(info r);
2690+
26862691
consteval bool is_template(info r);
26872692
consteval bool is_function_template(info r);
26882693
consteval bool is_variable_template(info r);
@@ -2715,6 +2720,9 @@
27152720
consteval bool has_template_arguments(info r);
27162721
consteval info template_of(info r);
27172722
consteval vector<info> template_arguments_of(info r);
2723+
consteval vector<info> parameters_of(info r);
2724+
consteval info variable_of(info r);
2725+
consteval info return_type_of(info r);
27182726

27192727
// \ref{meta.reflection.access.context}, access control context
27202728
struct access_context;
@@ -3238,6 +3246,47 @@
32383246
operator function template,
32393247
or conversion function template.
32403248
Otherwise, \tcode{false}.
3249+
\item
3250+
Otherwise, if \tcode{r} represents the $i^\text{th}$ parameter of a function $F$
3251+
that is an (implicit or explicit) specialization of a templated function $T$
3252+
and the $i^\text{th}$ parameter of the instantiated declaration of $T$
3253+
whose template arguments are those of $F$ would be instantiated from a pack,
3254+
then \tcode{false}.
3255+
\item
3256+
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
3257+
then let $S$ be the set of declarations,
3258+
ignoring any explicit instantiations,
3259+
that precede some point in the evaluation context
3260+
and that declare either $F$ or a templated function
3261+
of which $F$ is a specialization;
3262+
\tcode{true} if
3263+
\begin{itemize}
3264+
\item
3265+
there is a declaration $D$ in $S$ that introduces a name $N$ for either $P$
3266+
or the parameter corresponding to $P$
3267+
in the templated function that $D$ declares and
3268+
\item
3269+
no declaration in $S$ does so using any name other than $N$.
3270+
\end{itemize}
3271+
Otherwise, \tcode{false}.
3272+
\begin{example}
3273+
\begin{codeblock}
3274+
void fun(int);
3275+
constexpr std::meta::info r = parameters_of(^^fun)[0];
3276+
static_assert(!has_identifier(r));
3277+
3278+
void fun(int x);
3279+
static_assert(has_identifier(r));
3280+
3281+
void fun(int x);
3282+
static_assert(has_identifier(r));
3283+
3284+
void poison() {
3285+
void fun(int y);
3286+
}
3287+
static_assert(!has_identifier(r));
3288+
\end{codeblock}
3289+
\end{example}
32413290
\item
32423291
Otherwise, if \tcode{r} represents a variable,
32433292
then \tcode{false} if the declaration of that variable
@@ -3298,6 +3347,15 @@
32983347
\item
32993348
Otherwise, if \tcode{r} represents a literal operator or literal operator template,
33003349
then the \grammarterm{ud-suffix} of the operator or operator template.
3350+
\item
3351+
Otherwise, if \tcode{r} represents the parameter $P$ of a function $F$,
3352+
then let $S$ be the set of declarations,
3353+
ignoring any explicit instantiations,
3354+
that precede some point in the evaluation context
3355+
and that declare either $F$
3356+
or a templated function of which $F$ is a specialization;
3357+
the name that was introduced by a declaration in $S$
3358+
for the parameter corresponding to $P$.
33013359
\item
33023360
Otherwise, if \tcode{r} represents an entity,
33033361
then the identifier introduced by the declaration of that entity.
@@ -3378,8 +3436,9 @@
33783436
enumerator,
33793437
non-static data member,
33803438
unnamed bit-field,
3381-
direct base class relationship, or
3382-
data member description.
3439+
direct base class relationship,
3440+
data member description, or
3441+
function parameter.
33833442
Otherwise, \tcode{false}.
33843443
\end{itemdescr}
33853444

@@ -3397,7 +3456,11 @@
33973456
\returns
33983457
\begin{itemize}
33993458
\item
3400-
If \tcode{r} represents a
3459+
If \tcode{r} represents the $i^\text{th}$ parameter of a function $F$,
3460+
then the $i^\text{th}$ type
3461+
in the parameter-type-list of $F$\iref{dcl.fct}.
3462+
\item
3463+
Otherwise, if \tcode{r} represents a
34013464
value,
34023465
object,
34033466
variable,
@@ -3968,6 +4031,70 @@
39684031
Otherwise, \tcode{false}.
39694032
\end{itemdescr}
39704033

4034+
\indexlibraryglobal{is_function_parameter}%
4035+
\begin{itemdecl}
4036+
consteval bool is_function_parameter(info r);
4037+
\end{itemdecl}
4038+
4039+
\begin{itemdescr}
4040+
\pnum
4041+
\returns
4042+
\tcode{true} if \tcode{r} represents a function parameter.
4043+
Otherwise, \tcode{false}.
4044+
\end{itemdescr}
4045+
4046+
\indexlibraryglobal{is_explicit_object_parameter}%
4047+
\begin{itemdecl}
4048+
consteval bool is_explicit_object_parameter(info r);
4049+
\end{itemdecl}
4050+
4051+
\begin{itemdescr}
4052+
\pnum
4053+
\returns
4054+
\tcode{true} if \tcode{r} represents a function parameter
4055+
that is an explicit object parameter\iref{dcl.fct}.
4056+
Otherwise, \tcode{false}.
4057+
\end{itemdescr}
4058+
4059+
\indexlibraryglobal{has_default_argument}%
4060+
\begin{itemdecl}
4061+
consteval bool has_default_argument(info r);
4062+
\end{itemdecl}
4063+
4064+
\begin{itemdescr}
4065+
\pnum
4066+
\returns
4067+
If \tcode{r} represenst a parameter $P$ of a function $F$, then:
4068+
\begin{itemize}
4069+
\item
4070+
If $F$ is a specialization of a templated function $T$,
4071+
then \tcode{true} if there exists a declaration $D$ of $T$
4072+
that precedes some point in the evaluation context
4073+
and $D$ specifies a default argument
4074+
for the parameter of $T$ corresponding to $P$.
4075+
Otherwise, \tcode{false}.
4076+
\item
4077+
Otherwise, if there exists a declaration $D$ of $F$
4078+
that precedes some point in the evaluation context
4079+
and $D$ specifies a default argument for $P$,
4080+
then \tcode{true}.
4081+
\end{itemize}
4082+
Otherwise, \tcode{false}.
4083+
\end{itemdescr}
4084+
4085+
\indexlibraryglobal{has_ellipsis_parameter}%
4086+
\begin{itemdecl}
4087+
consteval bool has_ellipsis_parameter(info r);
4088+
\end{itemdecl}
4089+
4090+
\begin{itemdescr}
4091+
\pnum
4092+
\returns
4093+
\tcode{true} if \tcode{r} represents a function type
4094+
that has an ellipsis in its parameter-type-list\iref{dcl.fct}.
4095+
Otherwise, \tcode{false}.
4096+
\end{itemdescr}
4097+
39714098
\indexlibraryglobal{is_template}%
39724099
\begin{itemdecl}
39734100
consteval bool is_template(info r);
@@ -4266,7 +4393,7 @@
42664393
A \tcode{vector} containing reflections
42674394
of the template arguments
42684395
of the template specialization represented by \tcode{r},
4269-
in the order they appear in the corresponding template argument list.
4396+
in the order in which they appear in the corresponding template argument list.
42704397
For a given template argument $A$,
42714398
its corresponding reflection $R$ is determined as follows:
42724399
\begin{itemize}
@@ -4325,6 +4452,72 @@
43254452
\end{example}
43264453
\end{itemdescr}
43274454

4455+
\indexlibraryglobal{parameters_of}%
4456+
\begin{itemdecl}
4457+
consteval vector<info> parameters_of(info r);
4458+
\end{itemdecl}
4459+
4460+
\begin{itemdescr}
4461+
\pnum
4462+
\constantwhen
4463+
\tcode{r} represents a function or a function type.
4464+
4465+
\pnum
4466+
\returns
4467+
\begin{itemize}
4468+
\item
4469+
If \tcode{r} represents a function $F$,
4470+
then a \tcode{vector} containing reflections of the parameters of $F$,
4471+
in the order in which they appear in a declaration of $F$.
4472+
\item
4473+
Otherwise, \tcode{r} represents a function type $T$;
4474+
a \tcode{vector} containing reflections of the types
4475+
in parameter-type-list\iref{dcl.fct} of $T$,
4476+
in the order in which they appear in the parameter-type-list.
4477+
\end{itemize}
4478+
\end{itemdescr}
4479+
4480+
\indexlibraryglobal{variable_of}%
4481+
\begin{itemdecl}
4482+
consteval info variable_of(info r);
4483+
\end{itemdecl}
4484+
4485+
\begin{itemdescr}
4486+
\pnum
4487+
\constantwhen
4488+
\begin{itemize}
4489+
\item
4490+
\tcode{r} represents a parameter of a function $F$ and
4491+
\item
4492+
there is a point $P$ in the evaluation context
4493+
for which the innermost non-block scope enclosing $P$
4494+
is the function parameter scope\iref{basic.scope.param}
4495+
associated with $F$.
4496+
\end{itemize}
4497+
4498+
\pnum
4499+
\returns
4500+
The reflection of the parameter variable corresponding to \tcode{r}.
4501+
\end{itemdescr}
4502+
4503+
\indexlibraryglobal{return_type_of}%
4504+
\begin{itemdecl}
4505+
consteval info return_type_of(info r);
4506+
\end{itemdecl}
4507+
4508+
\begin{itemdescr}
4509+
\pnum
4510+
\constantwhen
4511+
Either \tcode{r} represents a function
4512+
and \tcode{\exposid{has-type}(r)} is \tcode{true}
4513+
or \tcode{r} represents a function type.
4514+
4515+
\pnum
4516+
\returns
4517+
The reflection of the return type
4518+
of the function or function type represented by \tcode{r}.
4519+
\end{itemdescr}
4520+
43284521
\rSec2[meta.reflection.access.context]{Access control context}
43294522

43304523
\pnum

0 commit comments

Comments
 (0)