This is the mail archive of the gcc-help@gcc.gnu.org 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]

Re: Exception problem with locale with g++ on Windows


On 2017/2/21 3:33, Marvin Gülker wrote:
the following program should switch to the current locale and then print
the name of that locale:
[...]
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 compiled and ran the program and it didn't generate any exceptions on my 64-bit Windows 7:

    E:\Desktop>g++ test.cc -std=c++14 -Wall -Wextra -pedantic

    E:\Desktop>a.exe
    Locale is now: C

    E:\Desktop>g++ --version
g++ (gcc-6-branch HEAD with MCF thread model, built by LH_Mouse.) 6.3.1 20170218
    Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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.
You are right. See [locale.cons]/6:

    explicit locale(const char* std_name);
    6 Remarks: The set of valid string argument values is "C", "", and
      any implementation-defined values.

Can someone please clarify what exactly is the problem with the C++
variant of this program, and how one can get it to work on Windows?

    $ g++ --version
    g++.exe (Rev1, Built by MSYS2 project) 6.3.0
    Copyright (C) 2016 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I can't reproduce this problem. It seems that your environment is broken. I have CC'd this message to the MSYS2 mailing list. Hope it helps.

--
Best regards,
LH_Mouse


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