<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 959</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="959"></A><H4>959.
  
Alignment attribute for class and enumeration types
</H4>
<B>Section: </B>9.13.2&#160; [<A href="https://wg21.link/dcl.align">dcl.align</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>Daveed Vandevoorde
 &#160;&#160;&#160;

 <B>Date: </B>31 August, 2009<BR>


<P>[Voted into WP at March, 2010 meeting.]</P>



<P>According to 9.13.2 [<A href="https://wg21.link/dcl.align#1">dcl.align</A>] 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.</P>

<P><B>Notes from the October, 2009 meeting:</B></P>

<P>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.</P>

<P><B>Proposed resolution (February, 2010):</B></P>

<OL>
<LI><P>Change 9.13.2 [<A href="https://wg21.link/dcl.align">dcl.align</A>] paragraphs 1-2 as
follows:</P></LI>

<BLOCKQUOTE>

<P>...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.
<INS>The attribute can also be applied to the declaration of a
class or enumeration type.</INS>
</P>

<P>When the alignment attribute is of the form
<TT>align(</TT><I>assignment-expression</I><TT>)</TT>:</P>

<UL>
<LI><P>...</P></LI>

<LI><P>if the constant expression evaluates to a fundamental
alignment, the alignment requirement of the declared
<DEL>object</DEL> <INS>entity</INS> shall be the specified
fundamental alignment</P></LI>

<LI><P>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
<DEL>object</DEL> <INS>entity</INS> shall be that
alignment</P></LI>

<LI><P>...</P></LI>

</UL>

</BLOCKQUOTE>

<LI><P>Change 9.13.2 [<A href="https://wg21.link/dcl.align">dcl.align</A>] paragraphs 4-6 as follows:</P></LI>

<BLOCKQUOTE>

<P>When multiple alignment attributes are specified for an
<DEL>object</DEL> <INS>entity</INS>, the alignment requirement
shall be set to the strictest specified alignment.</P>

<P>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
<DEL>object</DEL> <INS>entity</INS> being declared.</P>

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

</BLOCKQUOTE>

<LI><P>Insert the following as a new paragraph after
9.13.2 [<A href="https://wg21.link/dcl.align#6">dcl.align</A>] paragraph 6:</P></LI>

<BLOCKQUOTE>

<P><INS>[<I>Example:</I></INS></P>

<PRE>
<INS>  //<SPAN CLASS="cmnt"> Translation unit #1:</SPAN>
  struct S { int x; } s, p = &amp;s;

  //<SPAN CLASS="cmnt"> Translation unit #2:</SPAN>
  struct [[align(16)]] S;   //<SPAN CLASS="cmnt"> error: definition of </SPAN>S<SPAN CLASS="cmnt"> lacks alignment; no</SPAN>
  extern S* p;              //<SPAN CLASS="cmnt">            diagnostic required</SPAN></INS>
</PRE>

<P><INS>&#8212;<I>end example</I>]</INS></P>

</BLOCKQUOTE>

<LI><P>Delete 9.13.2 [<A href="https://wg21.link/dcl.align#8">dcl.align</A>] paragraph 8:</P></LI>

<BLOCKQUOTE>

<DEL>[<I>Note:</I> the alignment of a union type can be
strengthened by applying the alignment attribute to any
non-static data member of the union. &#8212;<I>end
note</I>]</DEL>

</BLOCKQUOTE>

</OL>

<BR><BR>
</BODY>
</HTML>
