Skip to content

Commit 69d8608

Browse files
authored
Merge 2025-06 CWG Motion 6
P3293R3 Splicing a base class subobject
2 parents d7ff520 + 0eb46ae commit 69d8608

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

source/expressions.tex

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,7 +4219,10 @@
42194219

42204220
\pnum
42214221
If \tcode{E2} is a \grammarterm{splice-expression},
4222-
then \tcode{E2} shall designate a member of the type of \tcode{E1}.
4222+
then let \tcode{T1} be the type of \tcode{E1}.
4223+
\tcode{E2} shall designate either
4224+
a member of the \tcode{T1} or
4225+
a direct base class relationship $(\tcode{T1}, \tcode{B})$.
42234226

42244227
\pnum
42254228
If \tcode{E2} designates a bit-field, \tcode{E1.E2} is a bit-field. The
@@ -4249,7 +4252,7 @@
42494252
\item Otherwise, if \tcode{E2} designates a non-static data member and the type of
42504253
\tcode{E1} is ``\cvqual{cq1 vq1} \tcode{X}'', and the type of \tcode{E2}
42514254
is ``\cvqual{cq2 vq2} \tcode{T}'', the expression designates the corresponding
4252-
member subobject of the object designated by the first expression. If \tcode{E1}
4255+
member subobject of the object designated by \tcode{E1}. If \tcode{E1}
42534256
is an lvalue, then \tcode{E1.E2} is an lvalue;
42544257
otherwise \tcode{E1.E2} is an xvalue.
42554258
Let the notation \cvqual{vq12} stand for the ``union'' of
@@ -4292,6 +4295,40 @@
42924295
is \tcode{T}, the expression \tcode{E1.E2} is a prvalue of type \tcode{T}
42934296
whose value is the value of the enumerator.
42944297

4298+
\item If \tcode{E2} designates a direct base class relationship $(D, B)$
4299+
and the type of \tcode{E1} is \cv{} \tcode{T},
4300+
the expression designates the direct base class subobject of type $B$
4301+
of the object designated by \tcode{E1}.
4302+
If \tcode{E1} is an lvalue,
4303+
then \tcode{E1.E2} is an lvalue;
4304+
otherwise, \tcode{E1.E2} is an xvalue.
4305+
The type of \tcode{E1.E2} is ``\cv{} \tcode{$B$}''.
4306+
\begin{note}
4307+
This can only occur in an expression of the form \tcode{e1.[:e2:]}.
4308+
\end{note}
4309+
\begin{example}
4310+
\begin{codeblock}
4311+
struct B {
4312+
int b;
4313+
};
4314+
struct C : B {
4315+
int get() const { return b; }
4316+
};
4317+
struct D : B, C { };
4318+
4319+
constexpr int f() {
4320+
D d = {1, {}};
4321+
4322+
// \tcode{b} unambiguously refers to the direct base class of type \tcode{B},
4323+
// not the indirect base class of type \tcode{B}
4324+
B& b = d.[: std::meta::bases_of(^^D, std::meta::access_context::current())[0] :];
4325+
b.b += 10;
4326+
return 10 * b.b + d.get();
4327+
}
4328+
static_assert(f() == 110);
4329+
\end{codeblock}
4330+
\end{example}
4331+
42954332
\item Otherwise, the program is ill-formed.
42964333
\end{itemize}
42974334

source/meta.tex

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,12 +2706,14 @@
27062706
consteval bool is_accessible(info r, access_context ctx);
27072707
consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx);
27082708
consteval bool has_inaccessible_bases(info r, access_context ctx);
2709+
consteval bool has_inaccessible_subobjects(info r, access_context ctx);
27092710

27102711
// \ref{meta.reflection.member.queries}, reflection member queries
27112712
consteval vector<info> members_of(info r, access_context ctx);
27122713
consteval vector<info> bases_of(info type, access_context ctx);
27132714
consteval vector<info> static_data_members_of(info type, access_context ctx);
27142715
consteval vector<info> nonstatic_data_members_of(info type, access_context ctx);
2716+
consteval vector<info> subobjects_of(info type, access_context ctx);
27152717
consteval vector<info> enumerators_of(info type_enum);
27162718

27172719
// \ref{meta.reflection.layout}, reflection layout queries
@@ -4589,6 +4591,20 @@
45894591
Otherwise, \tcode{false}.
45904592
\end{itemdescr}
45914593

4594+
\indexlibraryglobal{has_inaccessible_subobjects}%
4595+
\begin{itemdecl}
4596+
consteval bool has_inaccessible_subobjects(info r, access_context ctx);
4597+
\end{itemdecl}
4598+
4599+
\begin{itemdescr}
4600+
\pnum
4601+
\effects
4602+
Equivalent to:
4603+
\begin{codeblock}
4604+
return has_inaccessible_bases(r, ctx) || has_inaccessible_nonstatic_data_members(r, ctx);
4605+
\end{codeblock}
4606+
\end{itemdescr}
4607+
45924608
\rSec2[meta.reflection.member.queries]{Reflection member queries}
45934609

45944610
\indexlibraryglobal{members_of}%
@@ -4795,6 +4811,24 @@
47954811
preserving their order.
47964812
\end{itemdescr}
47974813

4814+
\indexlibraryglobal{subobjects_of}%
4815+
\begin{itemdecl}
4816+
consteval vector<info> subobjects_of(info type, access_context ctx);
4817+
\end{itemdecl}
4818+
4819+
\begin{itemdescr}
4820+
\pnum
4821+
\constantwhen
4822+
\tcode{dealias(type)} represents a class type
4823+
that is complete from some point in the evaluation context.
4824+
4825+
\pnum
4826+
\returns
4827+
A \tcode{vector} containing each element of \tcode{bases_of(type, ctx)}
4828+
followed by each element of \tcode{non\-static_data_mem\-bers_of(\brk{}type,\brk{} ctx)},
4829+
preserving their order.
4830+
\end{itemdescr}
4831+
47984832
\indexlibraryglobal{enumerators_of}%
47994833
\begin{itemdecl}
48004834
consteval vector<info> enumerators_of(info type_enum);

0 commit comments

Comments
 (0)