The following C++ program compiles without errors:
void f(char){}
void f(signed char){}
void f(unsigned char){}
int main(){}
The wchar_t
version of the same program does not:
void f(wchar_t){}
void f(signed wchar_t){}
void f(unsigned wchar_t){}
int main(){}
error: redefinition of ‘void f(wchar_t)’
void f(signed wchar_t){}
It seems that wchar_t
is unsigned
.
Why is there an inconsistency in overloading?
The char
s are all distinct types and can be overloaded
[basic.fundamental] / 1
[...] Plain
char
,signed char
, andunsigned char
are three distinct types, collectively called narrow character types. [...]
wchar_t
is also a distinct type, but it cannot be qualified with signed
or unsigned
, which can only be used with the standard integer types.
[dcl.type] / 2
As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration or in a type-specifier-seq or trailing-type-specifier-seq. The only exceptions to this rule are the following:
[...]
signed
orunsigned
can be combined withchar
,long
,short
, orint
.
[dcl.type.simple] / 2
[...] Table 9 summarizes the valid combinations of simple-type-specifiers and the types they specify.
The signedness of wchar_t
is implementation defined:
[basic.fundamental] / 5
[...] Type
wchar_t
shall have the same size, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlying type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With