Skip to content

Commit 5687674

Browse files
committed
P3293R3 Splicing a base class subobject
1 parent 178a7f4 commit 5687674

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
@@ -2705,12 +2705,14 @@
27052705
consteval bool is_accessible(info r, access_context ctx);
27062706
consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx);
27072707
consteval bool has_inaccessible_bases(info r, access_context ctx);
2708+
consteval bool has_inaccessible_subobjects(info r, access_context ctx);
27082709

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

27162718
// \ref{meta.reflection.layout}, reflection layout queries
@@ -4571,6 +4573,20 @@
45714573
Otherwise, \tcode{false}.
45724574
\end{itemdescr}
45734575

4576+
\indexlibraryglobal{has_inaccessible_subobjects}%
4577+
\begin{itemdecl}
4578+
consteval bool has_inaccessible_subobjects(info r, access_context ctx);
4579+
\end{itemdecl}
4580+
4581+
\begin{itemdescr}
4582+
\pnum
4583+
\effects
4584+
Equivalent to:
4585+
\begin{codeblock}
4586+
return has_inaccessible_bases(r, ctx) || has_inaccessible_nonstatic_data_members(r, ctx);
4587+
\end{codeblock}
4588+
\end{itemdescr}
4589+
45744590
\rSec2[meta.reflection.member.queries]{Reflection member queries}
45754591

45764592
\indexlibraryglobal{members_of}%
@@ -4777,6 +4793,24 @@
47774793
preserving their order.
47784794
\end{itemdescr}
47794795

4796+
\indexlibraryglobal{subobjects_of}%
4797+
\begin{itemdecl}
4798+
consteval vector<info> subobjects_of(info type, access_context ctx);
4799+
\end{itemdecl}
4800+
4801+
\begin{itemdescr}
4802+
\pnum
4803+
\constantwhen
4804+
\tcode{dealias(type)} represents a class type
4805+
that is complete from some point in the evaluation context.
4806+
4807+
\pnum
4808+
\returns
4809+
A \tcode{vector} containing each element of \tcode{bases_of(type, ctx)}
4810+
followed by each element of \tcode{non\-static_data_mem\-bers_of(\brk{}type,\brk{} ctx)},
4811+
preserving their order.
4812+
\end{itemdescr}
4813+
47804814
\indexlibraryglobal{enumerators_of}%
47814815
\begin{itemdecl}
47824816
consteval vector<info> enumerators_of(info type_enum);

0 commit comments

Comments
 (0)