In particular, arithmetic operators do not accept types smaller than int as arguments, and integral promotions are automatically applied after lvalue-to-rvalue conversion, if applicable.
All the major compilers (g++, clang, and msvc) say that decltype(a+b)
is int
when both a
and b
are short
.
However, the standard says:
Integral promotions [conv.prom]/1
A prvalue of an integer type other thanbool
,char16_t
,char32_t
, orwchar_t
whose integer conversion rank is less than the rank ofint
can be converted to a prvalue of typeint
[...].Usual arithmetic conversions [expr.arith.conv]/1.5.1
-- If both operands have the same type, no further conversion is needed.
I can only see that "can be converted" and I cannot find where it requires integral promotion for arithmetic operators.
Is the cppreference wrong here?