Exception problem with locale with g++ on Windows
Xi Ruoyao
ryxi@stu.xidian.edu.cn
Tue Feb 21 04:28:00 GMT 2017
On 2017-02-20 20:33 +0100, Marvin Gülker wrote:
> the following program should switch to the current locale and then
> print
> the name of that locale:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> #include <locale>
> #include <iostream>
>
> int main()
> {
> Â std::locale::global(std::locale(""));
>
> Â std::locale current_locale;
> Â std::cout << "Locale is now: " << current_locale.name() <<
> std::endl;
> Â return 0;
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> It appears, however, that it doesn't do that on my 32-bits Windows 7.
> The program compiles fine, but when I execute it, I get this (after
> the usual "application has requested the runtime yadda yadda"):
>
> Â Â Â Â terminate called after throwing an instance of
> 'std::runtime_error'
> Â Â Â Â Â Â what(): locale::facet::_S_create_c_locale name not valid
>
> (That is, an std::runtime_error exception is thrown by the
> constructor
> of std::locale)
>
> I used the locale name "" (empty string), which should refer to the
> environment's locale and should be available on any platform (I even
> think it is required to do that, but I don't have a C++ standard at
> hand). Using the "C" locale works, but any other value causes the
> above problem.
A comment in GCC source code
(libstdc++-v3/config/locale/generic/c_locale.cc) said:
  Currently, the generic model only supports the "C" locale.
  See http://gcc.gnu.org/ml/libstdc++/2003-02/msg00345.html
Read that thread and the follow-ups to get more information.
--
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University
More information about the Gcc-help
mailing list