This expression can be found in the example in clause 8.5.4 / 7 in the standard (N3797)
unsigned int ui1 = {-1};
Given §8.5.4 / 7 and its fourth marker point:
Narrowing a transform is an implicit transform:
- from an integer type or an non-enumerated enumeration type to an integer type that cannot represent all the values of the source type, except when the source is a constant expression, the value of which after the integral promotions will fit into the target type.
I would say that there is no narrowing, since -1 is a constant expression, the value of which, after whole advertising, fits into an unsigned int.
See also §4.5 / 1 on Integral Promotion :
A value of an integer type other than bool, char16_t, char32_t or wchar_t, whose integer conversion rank (4.13) is less than the rank of int can be converted to prvalue of type int if int can represent all values of the source type; otherwise, the original value may be converted to a prvalue of type unsigned int.
From 4.13 we have that rank -1 (an int) is equal to rank unsigned int and therefore can be converted to unsigned int.
Edit
Unfortunately, Jerry Coffin removed his answer from this thread. I believe that he was on the right track, if we agree that the current reading of the fourth marker point in § 8.5.5 / 7 is incorrect, then change it in the standard.
c ++ language-lawyer c ++ 11
Wake up brazil
source share