Files
cppdraft_translate/cppdraft/conv/prom.md
2025-10-25 03:02:53 +03:00

96 lines
4.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[conv.prom]
# 7 Expressions [[expr]](./#expr)
## 7.3 Standard conversions [[conv]](conv#prom)
### 7.3.7 Integral promotions [conv.prom]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L853)
For the purposes of [conv.prom],
a [*converted bit-field*](#def:bit-field,converted "7.3.7Integral promotions[conv.prom]") is a prvalue that is the result of
an lvalue-to-rvalue conversion ([[conv.lval]](conv.lval "7.3.2Lvalue-to-rvalue conversion")) applied to
a bit-field ([[class.bit]](class.bit "11.4.10Bit-fields"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L859)
A prvalue that is not a converted bit-field and has an integer type other thanbool, char8_t, char16_t,char32_t, or wchar_t whose integer conversion
rank ([[conv.rank]](conv.rank "6.9.6Conversion ranks")) is less than the rank of int can be
converted to a prvalue of type int if int can represent
all the values of the source type; otherwise, the source prvalue can be
converted to a prvalue of type unsigned int[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L869)
A prvalue of an unscoped enumeration type whose underlying type is not
fixed can be converted to a prvalue of the first of the following
types that can represent all the values of the enumeration ([[dcl.enum]](dcl.enum "9.8.1Enumeration declarations")): int,unsigned int, long int, unsigned long int,long long int, or unsigned long long int[.](#3.sentence-1)
If none of the types in that
list can represent all the values of the enumeration, a prvalue of an unscoped
enumeration type can be converted to a prvalue of the extended integer type with lowest
integer conversion rank ([[conv.rank]](conv.rank "6.9.6Conversion ranks")) greater than the rank of long long in which all the values of the enumeration can be represented[.](#3.sentence-2)
If there are
two such extended types, the signed one is chosen[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L882)
A prvalue of an unscoped enumeration type whose underlying type is
fixed ([[dcl.enum]](dcl.enum "9.8.1Enumeration declarations")) can be converted to a prvalue of its underlying type[.](#4.sentence-1)
Moreover,
if integral promotion can be applied to its underlying type, a prvalue of an unscoped
enumeration type whose underlying type is fixed can also be converted to a prvalue of
the promoted underlying type[.](#4.sentence-2)
[*Note [1](#note-1)*:
A converted bit-field of enumeration type is treated as
any other value of that type for promotion purposes[.](#4.sentence-3)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L893)
A converted bit-field of integral type can be converted
to a prvalue of type int if int can represent all the
values of the bit-field; otherwise, it can be converted tounsigned int if unsigned int can represent all the
values of the bit-field[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L900)
A prvalue of typechar8_t, char16_t, char32_t, orwchar_t ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))
(including a converted bit-field that was not
already promoted to int or unsigned int according to the rules above)
can be converted to a prvalue
of the first of the following types that can represent all the values of
its underlying type:int,unsigned int,long int,unsigned long int,long long int,unsigned long long int, or
its underlying type[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L921)
A prvalue of type bool can be converted to a prvalue of typeint, with false becoming zero and true becoming
one[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L927)
These conversions are called [*integral promotions*](#def:integral_promotion "7.3.7Integral promotions[conv.prom]")[.](#8.sentence-1)