问题描述
所有主要编译器(g ++,clang和msvc)说 decltype(a+b)
是<a
和b
均为short
时的c1>.
All the major compilers (g++, clang, and msvc) say that decltype(a+b)
is int
when both a
and b
are short
.
但是,标准说:
常用算术转换[expr.arith.conv]/1.5 .1
-如果两个操作数具有相同的类型,则无需进一步转换.
Usual arithmetic conversions [expr.arith.conv]/1.5.1
-- If both operands have the same type, no further conversion is needed.
我只能看到可以转换",也找不到在哪里需要对算术运算符进行整数提升.
cppreference在这里错误吗?
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?
推荐答案
您离它只有一线之遥.来自[expr]/11(N4659):
You were one line away from it. From [expr]/11 (N4659):
...
否则,必须对两个操作数执行积分提升(7.6) .然后,将以下规则应用于提升后的操作数:
Otherwise, the integral promotions (7.6) shall be performed on both operands. Then the following rules shall be applied to the promoted operands:
已添加重点. [conv.prom]说,它们可以发生并且如何工作. [expr]/11指定发生 的次数之一.
Emphasis added. [conv.prom] says that they can take place and how they work. [expr]/11 specifies one of the times when they will take place.
这篇关于算术运算符是否必须将整数参数提升为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!