<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1816</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="1816"></A><H4>1816.
  
Unclear specification of bit-field values
</H4>
<B>Section: </B>7.3.9&#160; [<A href="https://wg21.link/conv.integral">conv.integral</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Hubert Tong
 &#160;&#160;&#160;

 <B>Date: </B>2013-12-02<BR>


<P>[Moved to DR at the November, 2014 meeting.]</P>



<P>7.3.9 [<A href="https://wg21.link/conv.integral#3">conv.integral</A>] paragraph 3 says, regarding integral
conversions,</P>

<BLOCKQUOTE>

If the destination type is signed, the value is unchanged if
it can be represented in the destination type (and bit-field
width); otherwise, the value is implementation-defined.

</BLOCKQUOTE>

<P>The values that can be represented in a bit-field are not
well specified, except for the correspondence with the values of
an enumeration in 9.8.1 [<A href="https://wg21.link/dcl.enum">dcl.enum</A>].  In particular, it is
not clear whether a bit-field has a sign bit and whether bit-fields
may have padding bits.</P>

<P>Another point to note in this wording: paragraph 1 describes
the context as</P>

<BLOCKQUOTE>

A prvalue of an integer type can be converted to a prvalue
of another integer type.

</BLOCKQUOTE>

<P>However, prvalues cannot be bit-fields, so the applicability of
the mention of &#8220;bit-field width&#8221; in paragraph 3 is
unclear.</P>

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

<OL>
<LI><P>Change 7.3.9 [<A href="https://wg21.link/conv.integral#3">conv.integral</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

If the destination type is signed, the value is unchanged if it can be
represented in the destination type <DEL>(and bit-field width)</DEL>;
otherwise, the value is implementation-defined.

</BLOCKQUOTE>

<LI><P>Change 7.6.1.6 [<A href="https://wg21.link/expr.post.incr#1">expr.post.incr</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...The result is a prvalue. The type of the result is the cv-unqualified
version of the type of the operand. <INS>If the operand is a bit-field that
cannot represent the incremented value, the resulting value of the
bit-field is implementation-defined.</INS> See also
7.6.6 [<A href="https://wg21.link/expr.add">expr.add</A>] and 7.6.19 [<A href="https://wg21.link/expr.assign">expr.assign</A>].

</BLOCKQUOTE>

<LI><P>Change 7.6.19 [<A href="https://wg21.link/expr.assign#6">expr.assign</A>] paragraph 6 as follows:</P></LI>

<BLOCKQUOTE>

When the left operand of an assignment operator <DEL>denotes a reference
to <TT>T</TT>, the operation assigns to the object of type <TT>T</TT>
denoted by the reference</DEL> <INS>is a bit-field that cannot represent
the value of the expression, the resulting value of the bit-field is
implementation-defined.</INS>.

</BLOCKQUOTE>

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

<BLOCKQUOTE>

<P>The semantics of initializers are as follows...</P>

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

<LI><P>...no user-defined conversions are considered. If the conversion
cannot be done, the initialization is ill-formed. <INS>When initializing a
bit-field with a value that it cannot represent, the resulting value of the
bit-field is implementation-defined.</INS> [<I>Note:</I> An expression of
type...</P></LI>

</UL>

</BLOCKQUOTE>

</OL>

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