c++/4301: gcc 3.0.1 thinks wchar_t is a signed type when it's not

sebor@roguewave.com sebor@roguewave.com
Tue Sep 11 08:36:00 GMT 2001


>Number:         4301
>Category:       c++
>Synopsis:       gcc 3.0.1 thinks wchar_t is a signed type when it's not
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 11 08:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     sebor@roguewave.com
>Release:        3.0.1
>Organization:
>Environment:

>Description:
The compiler complains about comparisons between wchar_t and
values of unsigned types. The C++ library's numeric_limits
claims that wchar_t is a signed type. However, values of
wchar_t clearly behave as unsigned. The behavior is the
same in 2.95.2 (except for the C++ library part).

Regards
Martin
>How-To-Repeat:
$ cat t.cpp ; gcc -Wall t.cpp && ./a.out
#include <limits>
#include <cstdio>

int main ()
{
    unsigned a = 0;
    wchar_t b = -1;

    std::printf ("std::numeric_limits<unsigned>::is_signed = %d\n",
                 std::numeric_limits<unsigned>::is_signed);

    std::printf ("std::numeric_limits<wchar_t>::is_signed = %d\n", 
                 std::numeric_limits<wchar_t>::is_signed);

    std::printf ("wchar_t (-1) < 0 = %d\n", b < a);
}

t.cpp: In function `int main()':
t.cpp:15: warning: comparison between signed and unsigned integer expressions
std::numeric_limits<unsigned>::is_signed = 0
std::numeric_limits<wchar_t>::is_signed = 1
wchar_t (-1) < 0 = 0
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list