I have found a possible contradiction in the working draft of standard C++. First I present the facts, and my question comes at the end.
When the integer conversion ranks are established, [conv.rank]/1.1 says
No two signed integer types [...] shall have the same integer conversion rank, even if they have the same representation.
[basic.fundamental]/8 says:
Type
wchar_t
is a distinct type that has an implementation-defined signed or unsigned integer type as its underlying type.
Finally, [conv.rank]/1.8:
The ranks of
char8_t
,char16_t
,char32_t
, andwchar_t
shall equal the ranks of their underlying types ([basic.fundamental]).
In case that wchar_t
be implemented as a signed integer type, it would have the same rank as its underlying type, which is a distinct type of some other integer type.
Thus, we have two different signed integer types with identical rank, in contradiction with [conv.rank]/1.1.
Is this an actual contradiction, or I am misunderstanding when two trivially copyable types are distinct types in C++?
we have two different signed integer types
I see nowhere in the standard that it says that wchar_t
is a "signed integer type". Or an "unsigned integer type". I see where it says that it is an "integer type":
Types bool, char, wchar_t, char8_t, char16_t, char32_t, and the signed and unsigned integer types are collectively called integral types. A synonym for integral type is integer type.
But the definition of "signed integer type" does not include wchar_t
. That is, the standard clearly allows for the existence of "integer types" that are neither "signed integer types" nor "unsigned integer types".
And the statement from [conv.rank] does not apply to such types.