This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-01-02


2981. Usual arithmetic conversions and result types

Section: 7.4  [expr.arith.conv]     Status: open     Submitter: Jan Schultke     Date: 2025-01-02

(From submission #663.)

Subclause 7.4 [expr.arith.conv] paragraph 1 specifies:

Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. ...

However, while the relational and equality operators do apply the usual arithmetic conversions, their result type is bool and not the common type from the usual arithmetic conversions.

Suggested resolution:

  1. Change in 7.4 [expr.arith.conv] paragraph 1 as follows:

    Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. ...
  2. Change in 7.6.5 [expr.mul] paragraph 2 as follows:

    The operands of * and / shall have arithmetic or unscoped enumeration type; the operands of % shall have integral or unscoped enumeration type. The usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on the operands to bring them to a common type, and determine the type of the result is a prvalue of that type.
  3. Change in 7.6.6 [expr.add] paragraph 1 as follows:

    The additive operators + and - group left-to-right. Each operand shall be a prvalue. The result is a prvalue. If both operands have arithmetic or unscoped enumeration type, the usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on the operands to bring them to a common type, and the result is of that type. Otherwise, if one operand has arithmetic or unscoped enumeration type, integral promotion is applied (7.3.7 [conv.prom]) to that operand. A converted or promoted operand is used in place of the corresponding original operand for the remainder of this section.
  4. Change in 7.6.9 [expr.rel] paragraph 2 as follows:

    The converted operands shall have arithmetic, enumeration, or pointer type. The operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) all yield prvalues of false or true. The type of the result is bool.
  5. Change in 7.6.10 [expr.eq] paragraph 2 as follows:

    The converted operands shall have scalar type. The operators == and != both yield true or false, i.e., a result prvalue of type bool. In each case below, the operands shall have the same type after the specified conversions have been applied.
  6. Change in 7.6.11 [expr.bit.and] paragraph 1 as follows:

    The & operator groups left-to-right. The operands shall be of integral or unscoped enumeration type. The usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on the operands to bring them to a common type, and the result is a prvalue of that type. Given the coefficients xi and yi of the base-2 representation (6.8.2 [basic.fundamental]) of the converted operands x and y, the coefficient ri of the base-2 representation of the result r is 1 if both xi and yi are 1, and 0 otherwise.
  7. Change in 7.6.12 [expr.xor] paragraph 1 as follows:

    The ^ operator groups left-to-right. The operands shall be of integral or unscoped enumeration type. The usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on the operands to bring them to a common type, and the result is a prvalue of that type. Given the coefficients xi and yi of the base-2 representation (6.8.2 [basic.fundamental]) of the converted operands x and y, the coefficient ri of the base-2 representation of the result r is 1 if either (but not both) of xi and yi is 1, and 0 otherwise.
  8. Change in 7.6.13 [expr.or] paragraph 1 as follows:

    The | operator groups left-to-right. The operands shall be of integral or unscoped enumeration type. The usual arithmetic conversions (7.4 [expr.arith.conv]) are performed on the operands to bring them to a common type, and the result is a prvalue of that type. Given the coefficients xi and yi of the base-2 representation (6.8.2 [basic.fundamental]) of the converted operands x and y, the coefficient ri of the base-2 representation of the result r is 1 if at least one of xi and yi is 1, and 0 otherwise.