Title
Alignment attribute for class and enumeration types
Status
cd2
Section
9.12.2 [dcl.align]
Submitter
Daveed Vandevoorde

Created on 2009-08-31.00:00:00 last changed 179 months ago

Messages

Date: 2010-03-15.00:00:00

[Voted into WP at March, 2010 meeting.]

Date: 2010-02-15.00:00:00

Proposed resolution (February, 2010):

  1. Change 9.12.2 [dcl.align] paragraphs 1-2 as follows:

  2. ...The attribute can be applied to a variable that is neither a function parameter nor declared with the register storage class specifier and to a class data member that is not a bit-field. The attribute can also be applied to the declaration of a class or enumeration type.

    When the alignment attribute is of the form align(assignment-expression):

    • ...

    • if the constant expression evaluates to a fundamental alignment, the alignment requirement of the declared object entity shall be the specified fundamental alignment

    • if the constant expression evaluates to an extended alignment and the implementation supports that alignment in the context of the declaration, the alignment of the declared object entity shall be that alignment

    • ...

  3. Change 9.12.2 [dcl.align] paragraphs 4-6 as follows:

  4. When multiple alignment attributes are specified for an object entity, the alignment requirement shall be set to the strictest specified alignment.

    The combined effect of all alignment attributes in a declaration shall not specify an alignment that is less strict than the alignment that would otherwise be required for the object entity being declared.

    If the defining declaration of an object entity has an alignment attribute, any non-defining declaration of that object entity shall either specify equivalent alignment or have no alignment attribute. Conversely, if any declaration of an entity has an alignment attribute, every defining declaration of that entity shall specify an equivalent alignment. No diagnostic is required if declarations of an object entity have different alignment attributes in different translation units.

  5. Insert the following as a new paragraph after 9.12.2 [dcl.align] paragraph 6:

  6. [Example:

      // Translation unit #1:
      struct S { int x; } s, p = &s;
    
      // Translation unit #2:
      struct [[align(16)]] S;   // error: definition of S lacks alignment; no
      extern S* p;              //            diagnostic required
    

    end example]

  7. Delete 9.12.2 [dcl.align] paragraph 8:

  8. [Note: the alignment of a union type can be strengthened by applying the alignment attribute to any non-static data member of the union. —end note]
Date: 2009-10-15.00:00:00

Notes from the October, 2009 meeting:

Although there was initial concern for how to integrate the suggested change into the type system, it was observed that current practice is to have the attribute affect only the layout, not the type.

Date: 2009-08-31.00:00:00

According to 9.12.2 [dcl.align] paragraph 1, an alignment attribute can be specified only for a variable or a class data member. The corresponding Microsoft and GNU attributes can be also specified for a class type, and this usage seems to be widespread. It should be permitted with the standard attribute and there seems no good reason not to do so for enumeration types, as well.

History
Date User Action Args
2010-03-29 00:00:00adminsetmessages: + msg2699
2010-03-29 00:00:00adminsetstatus: tentatively ready -> cd2
2010-02-16 00:00:00adminsetmessages: + msg2499
2010-02-16 00:00:00adminsetstatus: drafting -> tentatively ready
2009-11-08 00:00:00adminsetmessages: + msg2385
2009-11-08 00:00:00adminsetstatus: open -> drafting
2009-08-31 00:00:00admincreate