std::locale does not work here

Benjamin Kosnik bkoz@redhat.com
Tue Jun 22 06:47:00 GMT 2004


>Is there a way to test the locale string support? Stroustrup says in his 
>  C++ book, that there is a "runtime_error" exception thrown by the 
>std::locale's constructor, if the locale string argument is not 
>supported by the executing OS. But Cygwin & Debian/stable's gnu stdc++ 
>libs do not react on unsupported locale strings...
>
>Is there any gnu stdc++ lib port out there, that supports more than "C"?

To use named locales, you have to use the GNU locale configs, which are
used automatically on gcc-3.2.x and above, given a sufficient glibc
version.

If you are using gcc 3.0.x on debian, and testing locales, you're out of
luck: pre 3.2.x, there was no locale support.

However, regardless of the locale config, 

std::locale loc("$$§§§XXXYYY????!!!");

will throw a runtime error with gcc of sufficient vintage.

%$bld/H-x86-gcc.20040613/bin/g++ -O2 -static localetest.cc
localetest.cc:6:31: warning: trigraph ??! ignored, use -trigraphs to enable
<bkoz@roscoe> /home/bkoz %a.out
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
Abort (core dumped)

There has been some (rather unmotivated) talk of cleaning up and
porting the existing POSIX layer to more systems.

I'll be the first to tell you that the current documenation of locales
and io are both quite weak. Paolo and I are both interested in changing
this situation in the near term, but for now, I suggest you look here:

http://gcc.gnu.org/onlinedocs/libstdc++/configopts.html (--enable-clocale)
http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/locale.html

Also, I recommend the Langer Kreft book on iostreams and locales for
background info.

-benjamin



More information about the Libstdc++ mailing list