patch: remaining -Wall warnings

Benjamin Kosnik bkoz@cygnus.com
Fri Aug 13 14:33:00 GMT 1999


> Some of the template instantiations for wchar_t evoke warnings about
> comparing signed and unsigned values.  Turns out that gcc is using
> unsigned int for wint_t.  That seems like a dubious choice.  But I
> don't know what the standard requires of wint_t.
> 
> In one case, the code was comparing a wint_t to -2:
> 
> 	if (_M_istreambuf && _M_c > -2)

This is indeed a problem. The ISO C++ standard defines (21.1.3)

char_traits<char>:
char_type char
int_type int

char_traits<wchar_t>:
char_type wchar_t
int_type wint_t

Problem being that, as you've noticed, wint_t is typedefed to an unsigned 
value (on linux and solaris). 

This is weak, as char_traits<char> as a signed int_type, and 
char_traits<wchar_t> is unsigned. What a mess. 

I don't see any wint_t requirements in the c++ standard per se. I so see 
(21.1.2) 

typedef INT_T int_type

"INT_T shall be a type or class that can represent all the valid chars 
converted from the corresponding char_type variables, plus an end-of-file 
value, eof()."

This would seem to imply that long long might be a better choice, or 
wchar_t's that are int, and hosts that support an 8-byte long long. Hmm.

Uli, any thoughts?



As for the patch, it's fine. I'm holding back checking it in as this 
remaining error makes the library compilation bail as -Werror is on. 
Actually, I'll just turn this part off for now, and check it in. I 
did change to using the explicit cast notation (static_cast<>()). No big 
deal.

Thanks again,

-Benjamin



More information about the Libstdc++ mailing list