public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@Shaw.ca>
To: cygwin@cygwin.com
Cc: Martin Wege <martin.l.wege@gmail.com>
Subject: Re: std::runtime_error on std::locale("")
Date: Fri, 22 Sep 2023 06:01:11 -0600	[thread overview]
Message-ID: <b1efebbd-23a1-5ea6-9652-3f39cd662ddb@Shaw.ca> (raw)
In-Reply-To: <CANH4o6NpCTV8JRohOy9bWs+uVVLAMp+TBxQOqEfuPqxvfsGFHA@mail.gmail.com>

On 2023-09-21 23:56, Martin Wege via Cygwin wrote:
> On Thu, Sep 21, 2023 at 9:07 PM Christian Franke via Cygwin
> <cygwin@cygwin.com> wrote:
>>
>> Brian Inglis via Cygwin wrote:
>>> On 2023-09-21 10:28, Takashi Yano via Cygwin wrote:
>>>> On Fri, 22 Sep 2023 01:12:04 +0900
>>>> Takashi Yano wrote:
>>>>> I wonder why the following code throws std::runtime_error
>>>>> even though the LC_ALL is set to valid locale other than "C".
>>>>> This does not occur only when LC_ALL is set to "C".
>>>>> #include <locale>
>>>>> int main()
>>>>> {
>>>>>      std::locale("");
>>>>>      return 0;
>>>>> }
>>>>> In linux, this occurs only when the LC_ALL is set to invalid
>>>>> locale (i.e. locale that is not registered in system).

>>>> Similarly,
>>>> std::locale("ja_JP.UTF-8")
>>>> throws std::runtime_error in cygwin.

>>> Looks like the implementation does not like any default "" or explicit
>>> "en_US.UTF-8" strings there! See example at link and below; results
>>> are always the same:
>>>      https://en.cppreference.com/w/cpp/locale/locale
>>> #include <iostream>
>>> #include <locale>
>>> int main()
>>> {
>>>      std::wcout << "User-preferred locale setting is "
>>>             << std::locale().name().c_str() << '\n';
>>>      // on startup, the global locale is the "C" locale
>>>      std::wcout << 1000.01 << '\n';
>>>      // replace the C++ global locale and the "C" locale with the
>>> user-preferred locale
>>>      std::locale::global(std::locale(""));
>>>      // use the new global locale for future wide character output
>>>      std::wcout.imbue(std::locale());
>>>      // output the same number again
>>>      std::wcout << 1000.01 << '\n';
>>> }
>>> $ g++ -o c++locale{,.cc}
>>> $ ./c++locale
>>> User-preferred locale setting is C
>>> 1000.01
>>> terminate called after throwing an instance of 'std::runtime_error'
>>>    what():  locale::facet::_S_create_c_locale name not valid
>>> Aborted (core dumped)

>> According to libstdc++ source, the internal function
>> locale::facet::_S_create_c_locale() calls some __newlocale() which
>> apparently does not arrive at newlocale() from cygwin1.dll. But
>> cygstdc++-6.dll imports newlocale() from cygwin1.dll.

> So this is a BUG?

>> Only standard locale "C" and its alias "POSIX" work with C++ std::locale().
>>
>> The cygwin1.dll function newlocale() works as expected - except that it
>> does not set errno if the locale name is invalid.

As this is (presumably) conforming code from the reference website, this 
certainly appears as if the current Cygwin implmentation may be non-conforming, 
and less than useful for many users and uses.

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

  reply	other threads:[~2023-09-22 12:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 16:12 Takashi Yano
2023-09-21 16:28 ` Takashi Yano
2023-09-21 18:08   ` Brian Inglis
2023-09-21 19:06     ` Christian Franke
2023-09-22  4:08       ` Takashi Yano
2023-09-22  7:20         ` Christian Franke
2023-09-22  5:56       ` Martin Wege
2023-09-22 12:01         ` Brian Inglis [this message]
2023-09-22  6:48 ` ASSI
2023-09-23  8:23   ` Takashi Yano
2023-09-23  8:42     ` Takashi Yano
2023-09-27 10:50     ` Takashi Yano
2023-12-31  6:57       ` Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b1efebbd-23a1-5ea6-9652-3f39cd662ddb@Shaw.ca \
    --to=brian.inglis@shaw.ca \
    --cc=cygwin@cygwin.com \
    --cc=martin.l.wege@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).