Skip to content

Commit 3c75a4e

Browse files
burblebeetkoeppe
authored andcommitted
CWG2485 Bit-fields in integral promotions
1 parent 9e751a8 commit 3c75a4e

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

source/expressions.tex

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -829,29 +829,22 @@
829829

830830
\rSec2[conv.prom]{Integral promotions}
831831

832+
\pnum
833+
For the purposes of \ref{conv.prom},
834+
a \defnadj{converted}{bit-field} is a prvalue that is the result of
835+
an lvalue-to-rvalue conversion\iref{conv.lval} applied to
836+
a bit-field\iref{class.bit}.
837+
832838
\pnum
833839
\indextext{promotion!integral}%
834-
A prvalue of an integer type other than \keyword{bool}, \keyword{char8_t}, \keyword{char16_t},
840+
A prvalue that is not a converted bit-field and has an integer type other than
841+
\keyword{bool}, \keyword{char8_t}, \keyword{char16_t},
835842
\keyword{char32_t}, or \keyword{wchar_t} whose integer conversion
836843
rank\iref{conv.rank} is less than the rank of \keyword{int} can be
837844
converted to a prvalue of type \keyword{int} if \keyword{int} can represent
838845
all the values of the source type; otherwise, the source prvalue can be
839846
converted to a prvalue of type \tcode{\keyword{unsigned} \keyword{int}}.
840847

841-
\pnum
842-
\indextext{type!underlying!\idxcode{wchar_t}}%
843-
\indextext{type!underlying!\idxcode{char16_t}}%
844-
\indextext{type!underlying!\idxcode{char32_t}}%
845-
A prvalue of type \keyword{char8_t}, \keyword{char16_t}, \keyword{char32_t}, or
846-
\keyword{wchar_t}\iref{basic.fundamental} can be converted to a prvalue
847-
of the first of the following types that can represent all the values of
848-
its underlying type: \keyword{int}, \tcode{\keyword{unsigned} \keyword{int}}, \tcode{\keyword{long} \keyword{int}},
849-
\tcode{\keyword{unsigned} \keyword{long} \keyword{int}}, \tcode{\keyword{long} \keyword{long} \keyword{int}},
850-
or \tcode{\keyword{unsigned} \keyword{long} \keyword{long} \keyword{int}}. If none of the types in that list can
851-
represent all the values of its underlying type, a prvalue of type
852-
\keyword{char8_t}, \keyword{char16_t}, \keyword{char32_t}, or \keyword{wchar_t} can be converted
853-
to a prvalue of its underlying type.
854-
855848
\pnum
856849
\indextext{type!underlying!enumeration}%
857850
A prvalue of an unscoped enumeration type whose underlying type is not
@@ -871,15 +864,38 @@
871864
if integral promotion can be applied to its underlying type, a prvalue of an unscoped
872865
enumeration type whose underlying type is fixed can also be converted to a prvalue of
873866
the promoted underlying type.
867+
\begin{note}
868+
A converted bit-field of enumeration type is treated as
869+
any other value of that type for promotion purposes.
870+
\end{note}
874871

875872
\pnum
876-
A prvalue for an integral bit-field\iref{class.bit} can be converted
873+
A converted bit-field of integral type can be converted
877874
to a prvalue of type \keyword{int} if \keyword{int} can represent all the
878875
values of the bit-field; otherwise, it can be converted to
879876
\tcode{\keyword{unsigned} \keyword{int}} if \tcode{\keyword{unsigned} \keyword{int}} can represent all the
880-
values of the bit-field. If the bit-field is larger yet, no integral
881-
promotion applies to it. If the bit-field has enumeration type, it is
882-
treated as any other value of that type for promotion purposes.
877+
values of the bit-field.
878+
879+
\pnum
880+
\indextext{type!underlying!\idxcode{wchar_t}}%
881+
\indextext{type!underlying!\idxcode{char16_t}}%
882+
\indextext{type!underlying!\idxcode{char32_t}}%
883+
A prvalue of type
884+
\keyword{char8_t}, \keyword{char16_t}, \keyword{char32_t}, or
885+
\keyword{wchar_t}\iref{basic.fundamental}
886+
(including a converted bit-field that was not
887+
already promoted to \keyword{int} or \tcode{\keyword{unsigned} \keyword{int}}
888+
according to the rules above)
889+
can be converted to a prvalue
890+
of the first of the following types that can represent all the values of
891+
its underlying type:
892+
\keyword{int},
893+
\tcode{\keyword{unsigned} \keyword{int}},
894+
\tcode{\keyword{long} \keyword{int}},
895+
\tcode{\keyword{unsigned} \keyword{long} \keyword{int}},
896+
\tcode{\keyword{long} \keyword{long} \keyword{int}},
897+
\tcode{\keyword{unsigned} \keyword{long} \keyword{long} \keyword{int}}, or
898+
its underlying type.
883899

884900
\pnum
885901
\indextext{promotion!bool to int}%

0 commit comments

Comments
 (0)