This is the mail archive of the mailing list for the GCC 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]

Problem with --disable-c-mbchar and std::tolower

We're writing software that was ported from windows to unix, so it assumes 
that wchar_t is 2 bytes instead of 4 bytes.  We're using the -fshort-wchar 
gcc flag, but we've found that creating an std::basic_string of wchar_t 
cause all kinds of problems unless we configured gcc with the 
"--disable-c-mbchar" option. 

This was working fine for quite a while, but recently we discovered that 
calling std::tolower on a wchar_t with a locale argument causes a 
'bad_cast' exception to be thrown.

Code as simple as the following:
    wchar_t c = L'H';
    wchar_t c1 = std::tolower(c, std::locale());

will generate the bad_cast exception. 

What seems to be happening is that the use_facet code is looking at 
ctype<wchar_t>::_M_id(), finding that it is out of range ( it's greater 
than locale's _M_impl->_M_facets_size), and throwing the exception.    I'm 
assuming this is happening because "--disable-c-mbchar" is setting things 
up so that the wchar_t info isn't in the list of facets.

Any suggestions on how to resolve this?  The plans I'm considering are to 
find the STL code that adds the wchar_t info to the facet list and 
reintroducing it manually, or to turn off the disable-c-mbchar 
configuration option, and try to get things working like that.   But I 
must admit neither option sounds ideal to me, so I'd appreciate other 

I've tested this with both gcc 3.4.2 and 4.0.0 on linux/x86, Solaris 
9/sparc and HPUX11/pa-risc and I get the same behaviour everywhere - if 
the "--disable-c-mbchar" configuration option is used. 


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