This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ctype_members.cc broken when sizeof(mask) = 1


Development versions of NetBSD now have enough wide character support to 
trigger building the wchar_t support into libstdc++.  This has revealed 
some testsuite failures (I'd call them regressions in a way since the 
tests previously passed, though they were stubbed out).

It turns out that the problem on NetBSD is that 'mask' is defined to 
unsigned char.  But the _M_bit array (which is an array of 'mask') has the 
following initialization loop in generic/ctype_members.cc:

    for (size_t __i = 0; __i <= 15; ++__i)
      { 
        _M_bit[__i] = static_cast<mask>(1 << __i);
        _M_wmask[__i] = _M_convert_to_wmask(_M_bit[__i]);
      }  

Note that (char)(1 << 15) == 0.

This then causes bogus lookups when the code comes test the _M_bit array 
members.

It seems to have been this way since Ben added this code sometime in 2000.

I notice that several other platforms define mask as <char>, notably:

./config/os/newlib/ctype_base.h:    typedef char                mask;
./config/os/vxworks/ctype_base.h:    typedef unsigned char      mask;   
./config/os/bsd/netbsd/ctype_base.h:    typedef unsigned char           
mask;
./config/os/irix/irix5.2/ctype_base.h:    typedef unsigned char mask;
./config/os/solaris/solaris2.5/ctype_base.h:    typedef unsigned char   
mask;

so I'm a little surprised this hasn't come to light before.

Can anybody suggest a solution?  On NetBSD, simply changing mask to be 
unsigned int doesn't work because of other uses of mask for the real ctype 
code.  Does _M_bit really need to be an array of mask?

R.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]