This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2840. Missing requirements for fundamental alignments

Section: 6.7.6  [basic.align]     Status: open     Submitter: Jiang An     Date: 2023-08-31

(From submission #412.)

Consider:

struct S {
  long double d;
};

There appears to be no rule that prevents S from having an extended alignment. (See also WG14 DR445.)

Possible resolution:

  1. Change in 6.7.6 [basic.align] paragraph 2 as follows:

    A fundamental alignment is represented by an alignment less than or equal to the greatest alignment supported by the implementation in all contexts, which is equal to alignof(std::max_align_t) (17.2 [support.types]). Fundamental alignments shall be supported by the implementation for objects of all storage durations (6.7.5 [basic.stc]). The alignment required for a type may be different when it is used as the type of a complete object and when it is used as the type of a subobject. ...
  2. Change in 6.7.6 [basic.align] paragraph 3 as follows:

    An extended alignment is represented by an alignment greater than alignof(std::max_align_t). It is implementation-defined whether any extended alignments are supported and the contexts in storage durations for which they are supported (9.12.2 [dcl.align]). A type having an extended alignment requirement is an over-aligned type. [Note 1: Every over-aligned type is or contains a class type to which extended alignment applies (possibly through a non-static data member). —end note] [Note 2: The strictest supported alignment can be different for objects with different storage durations. —end note]
  3. Insert a new paragraph before 6.7.6 [basic.align] paragraph 4 and change as follows:

    Each of the following types has a fundamental alignment requirement:

    • a scalar type (6.8.1 [basic.types.general]),
    • an array type (9.3.4.5 [dcl.array]) whose element type has a fundamental alignment requirement, and
    • a class type (Clause 11 [class]) where all base classes and non-static data members have a type with a fundamental alignment requirement and no non-static data member is declared with an alignment-specifier (9.12.2 [dcl.align]) specifying an extended alignment.

    Alignments are represented as values of the type std::size_t. Valid alignments include only those values returned by an alignof expression for the fundamental types alignments plus an additional implementation-defined set of values, which may be empty. Every alignment value shall be a non-negative integral power of two.

  4. Change in 9.12.2 [dcl.align] paragraph 2 as follows:

    When the alignment-specifier is of the form alignas( constant-expression ):
    • the constant-expression shall be an integral constant expression and
    • if the constant expression does not evaluate to an alignment value (6.7.6 [basic.align]), or evaluates to an extended alignment and the implementation does not support that alignment in the context of the declaration for the storage duration (if any) of the entity being declared, the program is ill-formed.