Skip to content

Commit 903c608

Browse files
committed
Merge 2018-03 CWG Motion 2
2 parents cfd9720 + c5cc89b commit 903c608

File tree

5 files changed

+116
-32
lines changed

5 files changed

+116
-32
lines changed

source/basic.tex

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,27 +2755,55 @@
27552755
\defn{most derived object}.
27562756

27572757
\pnum
2758+
A \defn{potentially-overlapping subobject} is either:
2759+
\begin{itemize}
2760+
\item a base class subobject, or
2761+
\item a non-static data member
2762+
declared with the \tcode{no_unique_address} attribute\iref{dcl.attr.nouniqueaddr}.
2763+
\end{itemize}
2764+
2765+
\pnum
2766+
\indextext{object!zero size}%
2767+
\indextext{object!nonzero size}%
2768+
An object has nonzero size if it
2769+
\begin{itemize}
2770+
\item is not a potentially-overlapping subobject, or
2771+
\item is not of class type, or
2772+
\item is of a class type with virtual member functions or virtual base classes, or
2773+
\item has subobjects of nonzero size or bit-fields of nonzero length.
2774+
\end{itemize}
2775+
Otherwise, if the object is a base class subobject
2776+
of a standard-layout class type
2777+
with no non-static data members,
2778+
it has zero size.
2779+
Otherwise, the circumstances under which the object has zero size
2780+
are \impldef{which non-standard-layout objects
2781+
containing no data are considered empty}.
27582782
\indextext{most derived object!bit-field}%
2759-
Unless it is a bit-field\iref{class.bit}, a most derived object shall have a
2760-
nonzero size and shall occupy one or more bytes of storage. Base class
2761-
subobjects may have zero size. An object of trivially copyable or
2783+
Unless it is a bit-field\iref{class.bit},
2784+
an object with nonzero size
2785+
shall occupy one or more bytes of storage,
2786+
including every byte that is occupied in full or in part
2787+
by any of its subobjects.
2788+
An object of trivially copyable or
27622789
standard-layout type\iref{basic.types} shall occupy contiguous bytes of
27632790
storage.
27642791

27652792
\pnum
27662793
\indextext{most derived object!bit-field}%
27672794
\indextext{most derived object!zero size subobject}%
2768-
Unless an object is a bit-field or a base class subobject of zero size, the
2795+
Unless an object is a bit-field or a subobject of zero size, the
27692796
address of that object is the address of the first byte it occupies.
2770-
Two objects \placeholder{a} and \placeholder{b}
2797+
Two objects
27712798
with overlapping lifetimes
27722799
that are not bit-fields
27732800
may have the same address
27742801
if one is nested within the other,
27752802
or
2776-
if at least one is a base class subobject of zero size
2803+
if at least one is a subobject of zero size
27772804
and they are of different types;
2778-
otherwise, they have distinct addresses.\footnote{Under the ``as-if'' rule an
2805+
otherwise, they have distinct addresses
2806+
and occupy disjoint bytes of storage.\footnote{Under the ``as-if'' rule an
27792807
implementation is allowed to store two objects at the same machine address or
27802808
not store an object at all if the program cannot observe the
27812809
difference\iref{intro.execution}.}
@@ -2786,6 +2814,9 @@
27862814
const bool b = &test1 != &test2; // always \tcode{true}
27872815
\end{codeblock}
27882816
\end{example}
2817+
The address of a non-bit-field subobject of zero size is
2818+
the address of an unspecified byte of storage
2819+
occupied by the complete object of that subobject.
27892820

27902821
\pnum
27912822
\begin{note}
@@ -2963,9 +2994,8 @@
29632994
class type, does not contain any non-static data member whose type is
29642995
const-qualified or a reference type, and
29652996

2966-
\item the original object was a most derived object\iref{intro.object}
2967-
of type \tcode{T} and the new object is a most derived object of type
2968-
\tcode{T} (that is, they are not base class subobjects).
2997+
\item neither the original object nor the new object
2998+
is a potentially-overlapping subobject\iref{intro.object}.
29692999
\end{itemize}
29703000
\begin{example}
29713001
\begin{codeblock}
@@ -3573,7 +3603,7 @@
35733603
\pnum
35743604
\indextext{object!byte copying and|(}%
35753605
\indextext{type!trivially copyable}%
3576-
For any object (other than a base-class subobject) of trivially copyable type
3606+
For any object (other than a potentially-overlapping subobject) of trivially copyable type
35773607
\tcode{T}, whether or not the object holds a valid value of type
35783608
\tcode{T}, the underlying bytes\iref{intro.memory} making up the
35793609
object can be copied into an array of
@@ -3597,7 +3627,7 @@
35973627
\pnum
35983628
For any trivially copyable type \tcode{T}, if two pointers to \tcode{T} point to
35993629
distinct \tcode{T} objects \tcode{obj1} and \tcode{obj2}, where neither
3600-
\tcode{obj1} nor \tcode{obj2} is a base-class subobject, if the underlying
3630+
\tcode{obj1} nor \tcode{obj2} is a potentially-overlapping subobject, if the underlying
36013631
bytes\iref{intro.memory} making up
36023632
\tcode{obj1} are copied into \tcode{obj2},\footnote{By using, for example,
36033633
the library functions\iref{headers} \tcode{std::memcpy} or \tcode{std::memmove}.}

source/classes.tex

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@
101101
\end{example}
102102

103103
\pnum
104-
Complete objects and member subobjects of class type shall have nonzero
105-
size.\footnote{Base class subobjects are not so constrained.}
104+
\begin{note}
105+
Complete objects of class type have nonzero size.
106+
Base class subobjects and
107+
members declared with the \tcode{no_unique_address} attribute\iref{dcl.attr.nouniqueaddr}
108+
are not so constrained.
109+
\end{note}
110+
111+
\pnum
106112
\begin{note}
107113
Class objects can be assigned, passed as arguments to functions, and
108114
returned by functions (except objects of classes for which copying or moving has
@@ -175,8 +181,11 @@
175181
inherited\iref{class.derived}) non-static data members, the set
176182
$M(\mathtt{X})$ is empty.
177183

178-
\item If \tcode{X} is a non-union class type whose first non-static data
179-
member has type $\mathtt{X}_0$ (where said member may be an anonymous union),
184+
\item If \tcode{X} is a non-union class type with a non-static data
185+
member of type $\mathtt{X}_0$
186+
that is either of zero size or
187+
is the first non-static data member of \tcode{X}
188+
(where said member may be an anonymous union),
180189
the set $M(\mathtt{X})$ consists of $\mathtt{X}_0$ and the elements of
181190
$M(\mathtt{X}_0)$.
182191

@@ -193,8 +202,7 @@
193202
\end{itemize}
194203

195204
\begin{note} $M(\mathtt{X})$ is the set of the types of all non-base-class subobjects
196-
that are guaranteed in a standard-layout class to be at a zero offset
197-
in \tcode{X}. \end{note}
205+
that may be at a zero offset in \tcode{X}. \end{note}
198206

199207
\begin{example}
200208
\begin{codeblock}
@@ -743,8 +751,12 @@
743751
types is the longest sequence of non-static data
744752
members and bit-fields in declaration order, starting with the first
745753
such entity in each of the structs, such that corresponding entities
746-
have layout-compatible types and either neither entity is a bit-field or
747-
both are bit-fields with the same width.
754+
have layout-compatible types,
755+
either both entities are declared with
756+
the \tcode{no_unique_address} attribute\iref{dcl.attr.nouniqueaddr}
757+
or neither is,
758+
and either both entities are bit-fields with the same width
759+
or neither is a bit-field.
748760
\begin{example}
749761
\begin{codeblock}
750762
struct A { int a; char b; };

source/declarations.tex

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4141,3 +4141,42 @@
41414141
}
41424142
\end{codeblock}
41434143
\end{example}
4144+
4145+
\rSec2[dcl.attr.nouniqueaddr]{No unique address attribute}%
4146+
\indextext{attribute!no unique address}
4147+
4148+
\pnum
4149+
The \grammarterm{attribute-token} \tcode{no_unique_address}
4150+
specifies that a non-static data member
4151+
is a potentially-overlapping subobject\iref{intro.object}.
4152+
It shall appear at most once in each \grammarterm{attribute-list}
4153+
and no \grammarterm{attribute-argument-clause} shall be present.
4154+
The attribute may appertain to a non-static data member
4155+
other than a bit-field.
4156+
4157+
\pnum
4158+
\begin{note}
4159+
The non-static data member can share the address of
4160+
another non-static data member or that of a base class,
4161+
and any padding that would normally be inserted
4162+
at the end of the object
4163+
can be reused as storage for other members.
4164+
\end{note}
4165+
\begin{example}
4166+
\begin{codeblock}
4167+
template<typename Key, typename Value,
4168+
typename Hash, typename Pred, typename Allocator>
4169+
class hash_map {
4170+
[[no_unique_address]] Hash hasher;
4171+
[[no_unique_address]] Pred pred;
4172+
[[no_unique_address]] Allocator alloc;
4173+
Bucket *buckets;
4174+
// ...
4175+
public:
4176+
// ...
4177+
};
4178+
\end{codeblock}
4179+
Here, \tcode{hasher}, \tcode{pred}, and \tcode{alloc}
4180+
could have the same address as \tcode{buckets}
4181+
if their respective types are all empty.
4182+
\end{example}

source/expressions.tex

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,8 +3579,9 @@
35793579
\indextext{expression!\idxcode{sizeof}}%
35803580
\indextext{operator!\idxcode{sizeof}}%
35813581
\indextext{byte}%
3582-
The \tcode{sizeof} operator yields the number of bytes in the object
3583-
representation of its operand. The operand is either an expression,
3582+
The \tcode{sizeof} operator yields the number of bytes
3583+
occupied by a non-potentially-overlapping object of the type
3584+
of its operand. The operand is either an expression,
35843585
which is an unevaluated operand\iref{expr.prop}, or a parenthesized
35853586
\grammarterm{type-id}.
35863587
\indextext{type!incomplete}%
@@ -3611,12 +3612,14 @@
36113612
\indextext{class object!\idxcode{sizeof}}%
36123613
When applied to a class, the result is the number of bytes in an object
36133614
of that class including any padding required for placing objects of that
3614-
type in an array. The size of a most derived class shall be greater than
3615-
zero\iref{intro.object}. The result of applying \tcode{sizeof} to a
3616-
base class subobject is the size of the base class type.\footnote{The actual
3617-
size of a base class subobject may be less than the result of
3615+
type in an array.
3616+
The result of applying \tcode{sizeof} to a
3617+
potentially-overlapping subobject is
3618+
the size of the type, not the size of the subobject.%
3619+
\footnote{The actual size of a potentially-overlapping subobject
3620+
may be less than the result of
36183621
applying \tcode{sizeof} to the subobject, due to virtual base classes
3619-
and less strict padding requirements on base class subobjects.}
3622+
and less strict padding requirements on potentially-overlapping subobjects.}
36203623
\indextext{array!\idxcode{sizeof}}%
36213624
When applied to an array, the result is the total number of bytes in the
36223625
array. This implies that the size of an array of \term{n} elements is
@@ -5076,10 +5079,10 @@
50765079

50775080
\item If two pointers point to different non-static data members of the same
50785081
object, or to subobjects of such members, recursively,
5079-
the pointer to the later declared member compares greater provided the
5080-
two members
5081-
have the same access control\iref{class.access}
5082-
and provided their class is not a union.
5082+
the pointer to the later declared member compares greater provided
5083+
the two members have the same access control\iref{class.access},
5084+
neither member is a subobject of zero size,
5085+
and their class is not a union.
50835086

50845087
\item Otherwise, neither pointer compares greater than the other.
50855088

source/utilities.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15977,7 +15977,7 @@
1597715977
\tcode{template<class T>}\br
1597815978
\tcode{struct is_empty;} &
1597915979
\tcode{T} is a class type, but not a union type, with no non-static data
15980-
members other than bit-fields of length 0, no virtual member functions,
15980+
members other than subobjects of zero size, no virtual member functions,
1598115981
no virtual base classes, and no base class \tcode{B} for
1598215982
which \tcode{is_empty_v<B>} is \tcode{false}. &
1598315983
If \tcode{T} is a non-union class type, \tcode{T} shall be a complete type. \\ \rowsep

0 commit comments

Comments
 (0)