<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2253</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="2253"></A><H4>2253.
  
Unnamed bit-fields and zero-initialization
</H4>
<B>Section: </B>11.4.10&#160; [<A href="https://wg21.link/class.bit">class.bit</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Aaron Ballman
 &#160;&#160;&#160;

 <B>Date: </B>2016-03-23<BR>


<P>[Voted into the WP at the July, 2017 meeting.]</P>



<P>The current wording of the Standard does not clearly state that
zero-initialization applies to unnamed bit-fields.</P>

<P>
<B>Notes from the December, 2016 teleconference:</B>
</P>

<P>The consensus was that unnamed bit-fields do constitute padding;
more generally, padding should be normatively defined, along the lines
suggested in 11.4.10 [<A href="https://wg21.link/class.bit">class.bit</A>] paragraphs 1-2.</P>

<P><B>Proposed resolution (March, 2017):</B></P>

<OL>
<LI><P>Change 6.9 [<A href="https://wg21.link/basic.types#4">basic.types</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

The <I>object representation</I> of an object of type <TT>T</TT> is the
sequence of <I>N</I> <TT>unsigned char</TT> objects taken up by the object
of type <TT>T</TT>, where <I>N</I> equals <TT>sizeof(T)</TT>. The <I>value
representation</I> of an object is the set of bits that hold the value of
type <TT>T</TT>. <INS>Bits in the object representation that are not part
of the value representation are <I>padding bits</I>.</INS> For trivially
copyable types, the value representation is a set of bits in the object
representation that determines a <I>value</I>, which is one discrete
element of an implementation-defined set of values.<SUP>44</SUP>

</BLOCKQUOTE>

<LI><P>Change 9.5 [<A href="https://wg21.link/dcl.init#6">dcl.init</A>] paragraph 6 as follows:</P></LI>

<BLOCKQUOTE>

<P>To <I>zero-initialize</I> an object or reference of type <TT>T</TT>
means:</P>

<UL>
<LI><P>if <TT>T</TT> is a scalar type (6.9 [<A href="https://wg21.link/basic.types">basic.types</A>]), the
object is initialized to the value obtained by converting the integer
literal <TT>0</TT> (zero) to <TT>T</TT>;<SUP>103</SUP>
</P></LI>

<LI><P>if <TT>T</TT> is a (possibly cv-qualified) non-union class type,
<INS>its padding bits are initialized to zero bits and</INS> each
non-static data member and each base-class subobject is
zero-initialized<DEL> and padding is initialized to zero
bits</DEL>;</P></LI>

<LI><P>if <TT>T</TT> is a (possibly cv-qualified) union type, <INS>its
padding bits are initialized to zero bits and</INS> the object's first
non-static named data member is zero-initialized<DEL> and padding is
initialized to zero bits</DEL>;</P></LI>

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

</UL>

</BLOCKQUOTE>

<LI><P>Change 11.4.10 [<A href="https://wg21.link/class.bit#1">class.bit</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...The <I>constant-expression</I> shall be an integral constant expression
with a value greater than or equal to zero. The value of the integral
constant expression may be larger than the number of bits in the object
representation (6.9 [<A href="https://wg21.link/basic.types">basic.types</A>]) of the bit-field's type; in such
cases the extra bits are <DEL>used as</DEL> padding
bits <INS>(6.9 [<A href="https://wg21.link/basic.types">basic.types</A>])</INS><DEL>and do not participate in
the value representation (6.9 [<A href="https://wg21.link/basic.types">basic.types</A>]) of the
bit-field</DEL>. Allocation of bit-fields...

</BLOCKQUOTE>

<LI><P>Change 6.9.2 [<A href="https://wg21.link/basic.fundamental#1">basic.fundamental</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...For narrow character types, all bits of the object representation
participate in the value representation. [<I>Note:</I> A bit-field of
narrow character type whose length is larger than the number of bits in the
object representation of that type has padding bits; see
<DEL>11.4.10 [<A href="https://wg21.link/class.bit">class.bit</A>]</DEL>
<INS>6.9 [<A href="https://wg21.link/basic.types">basic.types</A>]</INS>. &#8212;<I>end note</I>] For unsigned
narrow character types...

</BLOCKQUOTE>

</OL>

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