This is the mail archive of the
mailing list for the libstdc++ project.
Re: V3 PATCH: numeric_limits<> support, fix PR/3865
Neil Booth <firstname.lastname@example.org> writes:
| Gabriel Dos Reis wrote:-
| > | > wchar_t is a keyword in C++, how do you easily test its signness with
| > | > if(0 or #if at compile-time and having that information in accordance
| > | > with the compiler's own idea?
| > |
| > | if (L'\0' - 1 < 0)
| > | wchar_t_is_signed;
| > | else
| > | wchar_t_is_unsigned;
| > That doesn't work with -fshort-wchar.
| It should do.
But it doesn't.
N_("Override the underlying type for wchar_t to `unsigned short'") },
Now, C++ rules require
L'\0' - 1
be evaluated after "the usual arithmetic conversions are performed".
The usual arithmetic conversions here say that (C++, 4.5/2):
An rvalue of type wchar_t (3.9.1) or an enumeration type (7.2) can
be converted to an rvalue of the first of the following types that
can represent all the values of its underlying type: int, unsigned
int, long, or unsigned long.
If "short" is 16-bit wide and int is 32-bit wide -- common assumptions,
especially on most (all?) GNU/Linux -- then the value
L'\0' - 1 is negative and wchar_t_is_signed is defined which is
clearly bogus since the underlying type will be "unsigned short".