Title
Usual arithmetic conversions and result types
Status
open
Section
7.4 [expr.arith.conv]
Submitter
Jan Schultke

Created on 2025-01-02.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-01-02.12:19:36

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.
Date: 2025-01-02.00:00:00

(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.

History
Date User Action Args
2025-01-02 12:19:36adminsetmessages: + msg7943
2025-01-02 00:00:00admincreate