Skip to content

Commit 39f1f09

Browse files
committed
P2996R13 Reflection for C++26
1 parent d81264a commit 39f1f09

File tree

10 files changed

+1910
-334
lines changed

10 files changed

+1910
-334
lines changed

source/basic.tex

Lines changed: 314 additions & 37 deletions
Large diffs are not rendered by default.

source/classes.tex

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@
555555
using-declaration\br
556556
using-enum-declaration\br
557557
static_assert-declaration\br
558+
consteval-block-declaration\br
558559
template-declaration\br
559560
explicit-specialization\br
560561
deduction-guide\br
@@ -646,13 +647,14 @@
646647
\end{note}
647648

648649
\pnum
649-
A \grammarterm{member-declaration} does not declare new members of the class
650+
A \grammarterm{member-declaration} does not itself declare new members of the class
650651
if it is
651652
\begin{itemize}
652653
\item a friend declaration\iref{class.friend},
653654
\item a \grammarterm{deduction-guide}\iref{temp.deduct.guide},
654655
\item a \grammarterm{template-declaration} whose \grammarterm{declaration} is one of the above,
655656
\item a \grammarterm{static_assert-declaration},
657+
\item a \grammarterm{consteval-block-declaration},
656658
\item a \grammarterm{using-declaration}\iref{namespace.udecl}, or
657659
\item an \grammarterm{empty-declaration}.
658660
\end{itemize}
@@ -686,10 +688,21 @@
686688
Any other data member or member function is a \defnadj{non-static}{member}
687689
(a \defnadj{non-static}{data member} or
688690
\defnadj{non-static}{member function}\iref{class.mfct.non.static}, respectively).
689-
\begin{note}
690-
A non-static data member of non-reference
691-
type is a member subobject of a class object\iref{intro.object}.
692-
\end{note}
691+
692+
\pnum
693+
Every object of class type has a unique member subobject
694+
corresponding to each of its direct non-static data members.
695+
If any non-static data member of a class \tcode{C} is of reference type,
696+
then let \tcode{D} be an invented class
697+
that is identical to \tcode{C}
698+
except that each non-static member of \tcode{D} corresponding to
699+
a member of \tcode{C} of type ``reference to \tcode{T}''
700+
instead has type ``pointer to \tcode{T}''.
701+
Every member subobject of a complete object of type \tcode{C}
702+
has the same size, alignment, and offset
703+
as that of the corresponding subobject of a complete object of type \tcode{D}.
704+
The size and alignment of \tcode{C} are the same as
705+
the size and alignment of \tcode{D}.
693706

694707
\pnum
695708
A member shall not be declared twice in the
@@ -999,6 +1012,46 @@
9991012
pointer-interconvertible\iref{basic.compound,expr.static.cast}.
10001013
\end{note}
10011014

1015+
\pnum
1016+
A \defnadj{data member}{description} is
1017+
a quintuple ($T$, $N$, $A$, $W$, $\mathit{NUA}$)
1018+
describing the potential declaration of a non-static data member where
1019+
\begin{itemize}
1020+
\item $T$ is a type,
1021+
\item $N$ is an identifier or $\bot$,
1022+
\item $A$ is an alignment or $\bot$,
1023+
\item $W$ is a bit-field width or $\bot$, and
1024+
\item $\mathit{NUA}$ is a boolean value.
1025+
\end{itemize}
1026+
Two data member descriptions are equal
1027+
if each of their respective components are the same entities,
1028+
are the same identifiers, have equal values, or are both $\bot$.
1029+
\begin{note}
1030+
The components of a data member description describe a data member such that
1031+
\begin{itemize}
1032+
\item
1033+
its type is specified using the type given by $T$,
1034+
\item
1035+
it is declared with the name given by $N$
1036+
if $N$ is not $\bot$ and is otherwise unnamed,
1037+
\item
1038+
it is declared with the \grammarterm{alignment-specifier}\iref{dcl.align}
1039+
given by \tcode{alignas($A$)}
1040+
if $A$ is not $\bot$ and
1041+
is otherwise declared without an \grammarterm{alignment-specifier},
1042+
\item
1043+
it is a bit-field\iref{class.bit} with the width given by $W$
1044+
if W is not $\bot$ and is otherwise not a bit-field, and
1045+
\item
1046+
it is declared with
1047+
the attribute \tcode{[[no_unique_address]]}\iref{dcl.attr.nouniqueaddr}
1048+
if $\mathit{NUA}$ is true and is otherwise declared without that attribute.
1049+
\end{itemize}
1050+
Data member descriptions are represented by reflections\iref{basic.fundamental}
1051+
returned by \tcode{std::meta::data_member_spec}\iref{meta.reflection.define.aggregate} and
1052+
can be reified as data members of a class using \tcode{std::meta::define_aggregate}.
1053+
\end{note}
1054+
10021055
\rSec2[class.mfct]{Member functions}%
10031056
\indextext{member function!class}
10041057

@@ -3515,7 +3568,12 @@
35153568
The class denoted by the \grammarterm{class-or-decltype} of
35163569
a \grammarterm{base-specifier} is called a
35173570
\defnadj{direct}{base class}
3518-
for the class being defined.
3571+
for the class being defined;
3572+
for each such \grammarterm{base-specifier},
3573+
the corresponding direct base class relationship
3574+
is the ordered pair (\tcode{D}, \tcode{B})
3575+
where \tcode{D} is the class being defined and
3576+
\tcode{B} is the direct base class.
35193577
\indextext{base class}%
35203578
\indextext{derivation|see{inheritance}}%
35213579
The lookup for the component name of
@@ -4346,9 +4404,10 @@
43464404
\end{codeblock}
43474405
\end{example}
43484406
\begin{note}
4349-
Because access control applies to the declarations named, if access control is applied to a
4350-
\grammarterm{typedef-name}, only the accessibility of the typedef or alias declaration itself is considered.
4351-
The accessibility of the entity referred to by the \grammarterm{typedef-name} is not considered.
4407+
Because access control applies to the declarations named,
4408+
if access control is applied to a type alias,
4409+
only the accessibility of the typedef or alias declaration itself is considered.
4410+
The accessibility of the underlying entity is not considered.
43524411
\begin{example}
43534412
\begin{codeblock}
43544413
class A {
@@ -4739,10 +4798,18 @@
47394798
to a pointer to a private or protected immediate base class of
47404799
\tcode{X}.
47414800
\end{note}
4742-
The access to a member is affected by the class in which the member is
4743-
named.
4744-
This naming class is
4745-
the class in whose scope name lookup performed a search that found the member.
4801+
An expression $E$ that designates a member \tcode{m}
4802+
has a \defnadj{designating}{class}
4803+
that affects the access to \tcode{m}.
4804+
This designating class is either
4805+
\begin{itemize}
4806+
\item
4807+
the innermost class of which \tcode{m} is directly a member
4808+
if $E$ is a \grammarterm{splice-expression} or
4809+
\item
4810+
the class in whose scope name lookup performed a search
4811+
that found \tcode{m} otherwise.
4812+
\end{itemize}
47464813
\begin{note}
47474814
This class can be explicit, e.g., when a
47484815
\grammarterm{qualified-id}
@@ -4754,7 +4821,7 @@
47544821
\grammarterm{qualified-id}
47554822
are used to name the member (as in
47564823
\tcode{p->T::m}),
4757-
the class naming the member is the class denoted by the
4824+
the class designating the member is the class designated by the
47584825
\grammarterm{nested-name-specifier}
47594826
of the
47604827
\grammarterm{qualified-id}
@@ -4765,11 +4832,13 @@
47654832
\tcode{m}
47664833
is accessible at the point
47674834
\placeholder{R}
4768-
when named in class
4835+
when designated in class
47694836
\tcode{N}
47704837
if
47714838
\begin{itemize}
47724839
\item
4840+
\tcode{m} is designated by a \grammarterm{splice-expression}, or
4841+
\item
47734842
\tcode{m}
47744843
as a member of
47754844
\tcode{N}
@@ -4837,10 +4906,10 @@
48374906
left operand (considered as a pointer in the
48384907
``\tcode{.}''
48394908
operator case) cannot be implicitly converted to a
4840-
pointer to the naming class of the right operand.
4909+
pointer to the designating class of the right operand.
48414910
\begin{note}
48424911
This requirement is in addition to the requirement that
4843-
the member be accessible as named.
4912+
the member be accessible as designated.
48444913
\end{note}
48454914

48464915
\rSec2[class.friend]{Friends}%

source/compatibility.tex

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@
1313

1414
\rSec2[diff.cpp23.lex]{\ref{lex}: Lexical conventions}
1515

16+
\diffref{lex.operators}
17+
\change
18+
New operator \tcode{\caret\caret}.
19+
\rationale
20+
Required for new features.
21+
\effect
22+
Valid \CppXXIII{} code that contains two consecutive \tcode{\caret} tokens
23+
can be ill-formed in this revision of \Cpp{}.
24+
\begin{example}
25+
\begin{codeblock}
26+
struct C { int operator^(int); };
27+
int operator^(int (C::*p)(int), C);
28+
int i = &C::operator^^C{}; // ill-formed; previously well-formed
29+
\end{codeblock}
30+
\end{example}
31+
1632
\diffref{lex.key}
1733
\change
1834
New keywords.
@@ -148,6 +164,22 @@
148164
\end{codeblock}
149165
\end{example}
150166

167+
\diffref{dcl.attr.grammar}
168+
\change
169+
New token \tcode{:]}.
170+
\rationale
171+
Required for new features.
172+
\effect
173+
Valid \CppXXIII{} code that contained an \grammarterm{attribute-specifier}
174+
with an \grammarterm{attribute-using-prefix}
175+
but no attributes and no whitespace is ill-formed in this revision of \Cpp{}.
176+
\begin{example}
177+
\begin{codeblock}
178+
struct [[using CC:]] C; // ill-formed; previously well-formed
179+
struct [[using DD: ]] D; // OK
180+
\end{codeblock}
181+
\end{example}
182+
151183
\rSec2[diff.cpp23.temp]{\ref{temp}: templates}
152184

153185
\diffref{temp.constr}

0 commit comments

Comments
 (0)