What happens when I use the unary minus operator with an unsigned zero integer literal, e.g. -0u
?
The 2003 C++ standard says in 5.3.1c7:
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.
But in the zero case, 2^n - 0 = 2^n, which can't fit in, because the values that can be held are [0,2^n-1].
So, is using the unary minus operator with unsigned zero integer an error? Or does the value that results(2^n) get converted using the modulo because we are trying to fit an out-of-range value in an unsigned?