This is the original message from gcc-help. I can't reproduce this 
problem on a 64-bit Chinese Windows 7. Any help will be appreciated.

-------- Forwarded Message --------
Subject: Exception problem with locale with g++ on Windows
Date: Mon, 20 Feb 2017 20:33:38 +0100
From: Marvin Gülker <m-guel...@phoenixmail.de>
To: gcc-h...@gcc.gnu.org

Hi everyone,

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.

Compare to the identical C program:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdio.h>
#include <locale.h>

int main()
{
   const char* str = setlocale(LC_ALL, "");
   printf("Locale set to %s\n", str);
   return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This program compiles and works as expected (on my system, it outputs
"Locale set to German_Germany.1252").

Some Internet research suggests that this problem has been seen by other
people as well, but I was not able to find a solution; in particular,
the solution to not adapt to the current user's locale is not acceptable
for a program intended to run under different locales.

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.

Greetings
Marvin

-- 
Blog: https://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Msys2-users mailing list
Msys2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/msys2-users

Reply via email to