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

2023-01-15


1615. Alignment of types, variables, and members

Section: 9.12.2  [dcl.align]     Status: CD4     Submitter: Richard Smith     Date: 2013-02-01

[Moved to DR at the November, 2014 meeting.]

According to 9.12.2 [dcl.align] paragraph 5,

The combined effect of all alignment-specifiers in a declaration shall not specify an alignment that is less strict than the alignment that would be required for the entity being declared if all alignment-specifiers were omitted (including those in other declarations).

Presumably the intent was “other declarations of the same entity,” but the wording as written could be read to make the following example well-formed (assuming alignof(int) is 4):

  struct alignas(4) A {
    alignas(8) int n;
  };
  struct alignas(8) B {
    char c;
  };
  alignas(1) B b;
  struct alignas(1) C : B {};
  enum alignas(8) E : int { k };
  alignas(4) E e = k;

Proposed resolution (February, 2014):

Change 9.12.2 [dcl.align] paragraph 5 as follows:

...if all alignment-specifiers appertaining to that entity were omitted (including those in other declarations). [Example:

  struct alignas(8) S {};
  struct alignas(1) U {
    S s;
  };   // Error: U specifies an alignment that is less strict than
       // if the alignas(1) were omitted.

end example]