Skip to content

Commit a8ddb94

Browse files
committed
[basic.align] Move the Alignment clause adjacent to the Object model
Alignment places additional restrictions on memory in the object model for any storage that is acquired, so belongs here.
1 parent 13ba96c commit a8ddb94

File tree

1 file changed

+99
-91
lines changed

1 file changed

+99
-91
lines changed

source/basic.tex

Lines changed: 99 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,100 @@
34533453
\end{note}
34543454
\indextext{object model|)}
34553455

3456+
\rSec2[basic.align]{Alignment}
3457+
3458+
\pnum
3459+
Object types have \defnx{alignment requirements}{alignment requirement!implementation-defined}\iref{basic.fundamental,basic.compound}
3460+
which place restrictions on the addresses at which an object of that type
3461+
may be allocated. An \defn{alignment} is an \impldef{alignment}
3462+
integer value representing the number of bytes between successive addresses
3463+
at which a given object can be allocated. An object type imposes an alignment
3464+
requirement on every object of that type; stricter alignment can be requested
3465+
using the alignment specifier\iref{dcl.align}.
3466+
Attempting to create an object\iref{intro.object} in storage that
3467+
does not meet the alignment requirements of the object's type
3468+
is undefined behavior.
3469+
3470+
\pnum
3471+
A \defnadj{fundamental}{alignment} is represented by an alignment
3472+
less than or equal to the greatest alignment supported by the implementation in
3473+
all contexts, which is equal to
3474+
\tcode{\keyword{alignof}(std::max_align_t)}\iref{support.types}.
3475+
The alignment required for a type may be different when it is used as the type
3476+
of a complete object and when it is used as the type of a subobject.
3477+
\begin{example}
3478+
\begin{codeblock}
3479+
struct B { long double d; };
3480+
struct D : virtual B { char c; };
3481+
\end{codeblock}
3482+
3483+
When \tcode{D} is the type of a complete object, it will have a subobject of
3484+
type \tcode{B}, so it must be aligned appropriately for a \tcode{\keyword{long} \keyword{double}}.
3485+
If \tcode{D} appears as a subobject of another object that also has \tcode{B}
3486+
as a virtual base class, the \tcode{B} subobject might be part of a different
3487+
subobject, reducing the alignment requirements on the \tcode{D} subobject.
3488+
\end{example}
3489+
The result of the \keyword{alignof} operator reflects the alignment
3490+
requirement of the type in the complete-object case.
3491+
3492+
\pnum
3493+
An \defnadj{extended}{alignment} is represented by an alignment
3494+
greater than \tcode{\keyword{alignof}(std::max_align_t)}. It is \impldef{support for extended alignments}
3495+
whether any extended alignments are supported and the contexts in which they are
3496+
supported\iref{dcl.align}. A type having an extended alignment
3497+
requirement is an \defnadj{over-aligned}{type}.
3498+
\begin{note}
3499+
Every over-aligned type is or contains a class type
3500+
to which extended alignment applies (possibly through a non-static data member).
3501+
\end{note}
3502+
A \defnadj{new-extended}{alignment} is represented by
3503+
an alignment greater than \mname{STDCPP_DEFAULT_NEW_ALIGNMENT}\iref{cpp.predefined}.
3504+
3505+
\pnum
3506+
Alignments are represented as values of the type \tcode{std::size_t}.
3507+
Valid alignments include only those values returned by an \keyword{alignof}
3508+
expression for the fundamental types plus an additional \impldef{alignment additional
3509+
values}
3510+
set of values, which may be empty.
3511+
Every alignment value shall be a non-negative integral power of two.
3512+
3513+
\pnum
3514+
Alignments have an order from \defnx{weaker}{alignment!weaker} to
3515+
\defnx{stronger}{alignment!stronger} or \defnx{stricter}{alignment!stricter} alignments. Stricter
3516+
alignments have larger alignment values. An address that satisfies an alignment
3517+
requirement also satisfies any weaker valid alignment requirement.
3518+
3519+
\pnum
3520+
The alignment requirement of a complete type can be queried using an
3521+
\keyword{alignof} expression\iref{expr.alignof}. Furthermore,
3522+
the narrow character types\iref{basic.fundamental} shall have the weakest
3523+
alignment requirement.
3524+
\begin{note}
3525+
This enables the ordinary character types to be used as the
3526+
underlying type for an aligned memory area\iref{dcl.align}.
3527+
\end{note}
3528+
3529+
\pnum
3530+
Comparing alignments is meaningful and provides the obvious results:
3531+
3532+
\begin{itemize}
3533+
\item Two alignments are equal when their numeric values are equal.
3534+
\item Two alignments are different when their numeric values are not equal.
3535+
\item When an alignment is larger than another it represents a stricter alignment.
3536+
\end{itemize}
3537+
3538+
\pnum
3539+
\begin{note}
3540+
The runtime pointer alignment function\iref{ptr.align}
3541+
can be used to obtain an aligned pointer within a buffer;
3542+
an \grammarterm{alignment-specifier}\iref{dcl.align}
3543+
can be used to align storage explicitly.
3544+
\end{note}
3545+
3546+
\pnum
3547+
If a request for a specific extended alignment in a specific context is not
3548+
supported by an implementation, the program is ill-formed.
3549+
34563550
\rSec2[basic.life]{Lifetime}
34573551

34583552
\pnum
@@ -4249,99 +4343,13 @@
42494343
deallocation function shall deallocate the storage referenced by the
42504344
pointer, ending the duration of the region of storage.
42514345

4252-
\rSec2[basic.align]{Alignment}
4346+
\rSec3[basic.stc.inherit]{Duration of subobjects}
42534347

42544348
\pnum
4255-
Object types have \defnx{alignment requirements}{alignment requirement!implementation-defined}\iref{basic.fundamental,basic.compound}
4256-
which place restrictions on the addresses at which an object of that type
4257-
may be allocated. An \defn{alignment} is an \impldef{alignment}
4258-
integer value representing the number of bytes between successive addresses
4259-
at which a given object can be allocated. An object type imposes an alignment
4260-
requirement on every object of that type; stricter alignment can be requested
4261-
using the alignment specifier\iref{dcl.align}.
4262-
Attempting to create an object\iref{intro.object} in storage that
4263-
does not meet the alignment requirements of the object's type
4264-
is undefined behavior.
4265-
4266-
\pnum
4267-
A \defnadj{fundamental}{alignment} is represented by an alignment
4268-
less than or equal to the greatest alignment supported by the implementation in
4269-
all contexts, which is equal to
4270-
\tcode{\keyword{alignof}(std::max_align_t)}\iref{support.types}.
4271-
The alignment required for a type may be different when it is used as the type
4272-
of a complete object and when it is used as the type of a subobject.
4273-
\begin{example}
4274-
\begin{codeblock}
4275-
struct B { long double d; };
4276-
struct D : virtual B { char c; };
4277-
\end{codeblock}
4278-
4279-
When \tcode{D} is the type of a complete object, it will have a subobject of
4280-
type \tcode{B}, so it must be aligned appropriately for a \tcode{\keyword{long} \keyword{double}}.
4281-
If \tcode{D} appears as a subobject of another object that also has \tcode{B}
4282-
as a virtual base class, the \tcode{B} subobject might be part of a different
4283-
subobject, reducing the alignment requirements on the \tcode{D} subobject.
4284-
\end{example}
4285-
The result of the \keyword{alignof} operator reflects the alignment
4286-
requirement of the type in the complete-object case.
4287-
4288-
\pnum
4289-
An \defnadj{extended}{alignment} is represented by an alignment
4290-
greater than \tcode{\keyword{alignof}(std::max_align_t)}. It is \impldef{support for extended alignments}
4291-
whether any extended alignments are supported and the contexts in which they are
4292-
supported\iref{dcl.align}. A type having an extended alignment
4293-
requirement is an \defnadj{over-aligned}{type}.
4294-
\begin{note}
4295-
Every over-aligned type is or contains a class type
4296-
to which extended alignment applies (possibly through a non-static data member).
4297-
\end{note}
4298-
A \defnadj{new-extended}{alignment} is represented by
4299-
an alignment greater than \mname{STDCPP_DEFAULT_NEW_ALIGNMENT}\iref{cpp.predefined}.
4300-
4301-
\pnum
4302-
Alignments are represented as values of the type \tcode{std::size_t}.
4303-
Valid alignments include only those values returned by an \keyword{alignof}
4304-
expression for the fundamental types plus an additional \impldef{alignment additional
4305-
values}
4306-
set of values, which may be empty.
4307-
Every alignment value shall be a non-negative integral power of two.
4308-
4309-
\pnum
4310-
Alignments have an order from \defnx{weaker}{alignment!weaker} to
4311-
\defnx{stronger}{alignment!stronger} or \defnx{stricter}{alignment!stricter} alignments. Stricter
4312-
alignments have larger alignment values. An address that satisfies an alignment
4313-
requirement also satisfies any weaker valid alignment requirement.
4314-
4315-
\pnum
4316-
The alignment requirement of a complete type can be queried using an
4317-
\keyword{alignof} expression\iref{expr.alignof}. Furthermore,
4318-
the narrow character types\iref{basic.fundamental} shall have the weakest
4319-
alignment requirement.
4320-
\begin{note}
4321-
This enables the ordinary character types to be used as the
4322-
underlying type for an aligned memory area\iref{dcl.align}.
4323-
\end{note}
4324-
4325-
\pnum
4326-
Comparing alignments is meaningful and provides the obvious results:
4327-
4328-
\begin{itemize}
4329-
\item Two alignments are equal when their numeric values are equal.
4330-
\item Two alignments are different when their numeric values are not equal.
4331-
\item When an alignment is larger than another it represents a stricter alignment.
4332-
\end{itemize}
4333-
4334-
\pnum
4335-
\begin{note}
4336-
The runtime pointer alignment function\iref{ptr.align}
4337-
can be used to obtain an aligned pointer within a buffer;
4338-
an \grammarterm{alignment-specifier}\iref{dcl.align}
4339-
can be used to align storage explicitly.
4340-
\end{note}
4341-
4342-
\pnum
4343-
If a request for a specific extended alignment in a specific context is not
4344-
supported by an implementation, the program is ill-formed.
4349+
\indextext{storage duration!class member}%
4350+
The storage duration of subobjects and reference members
4351+
is that of their complete object\iref{intro.object}.
4352+
\indextext{storage duration|)}%
43454353

43464354
\rSec2[class.temporary]{Temporary objects}
43474355

0 commit comments

Comments
 (0)