为什么一元运算符 return 与其操作数的类型不同?

why do unary operators return different type than their operands?

看起来好像 uint16_t 和 uint8_t returns int 上的一元按位非运算符 (~), 而不是其操作数的类型(与一元 - 相同)。 有人可以说明为什么会这样吗?

令人惊讶的是 ~uint16_t(0) < uint16_t(0)

我使用g++版本9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2) x86_64-linux-gnu

来自 C++11 Standard 5.3.1.8:

The operand of the unary - operator shall have arithmetic or unscoped enumeration type and the result is the negation of its operand. Integral promotion is performed on integral or enumeration operands. The negative of an unsigned quantity is computed by subtracting its value from 2^n, where n is the number of bits in the promoted operand. The type of the result is the type of the promoted operand.

所以它指出整数提升发生在一元运算符上。