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