delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/09/22/08:01:51

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC768385702F
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1695384110;
bh=kaoel6UMskJW5FeYpZUDhE4bVwEGYmoaG4K5REDAYXg=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=c0ibH6iaqWaNi1kBoWtKE3oXwBxkK2/qEzsgxrfMJzvFTsqoAjolzlrXSHFse6DQg
6b4uI+5kYVHbyKDZTWZi9WijbPQaj5FT87zEPaMnHcfDEMCymyEARPNyQkW+KRuacX
jxHtuT1O6scRcUeeIuUXtFYJe83DEYDGVCxPhaeY=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7B7D3858D39
X-Authority-Analysis: v=2.4 cv=e5oV9Il/ c=1 sm=1 tr=0 ts=650d8208
a=DxHlV3/gbUaP7LOF0QAmaA==:117 a=DxHlV3/gbUaP7LOF0QAmaA==:17
a=IkcTkHD0fZMA:10 a=w_pzkKWiAAAA:8 a=2QSLavsyAAAA:8 a=asGUf2mW8sNpLXJpbdIA:9
a=QEXdDO2ut3YA:10 a=sRI3_1zDfAgwuvI8zelB:22 a=9H_80fVQ3bbXSWzY4Kdq:22
Message-ID: <b1efebbd-23a1-5ea6-9652-3f39cd662ddb@Shaw.ca>
Date: Fri, 22 Sep 2023 06:01:11 -0600
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Subject: Re: std::runtime_error on std::locale("")
To: cygwin AT cygwin DOT com
References: <20230922011204 DOT bb166498090e6cbe163349f3 AT nifty DOT ne DOT jp>
<20230922012856 DOT 47872090281f2a303fd7b99f AT nifty DOT ne DOT jp>
<0fab8831-c206-14fe-4350-3092e62fca98 AT Shaw DOT ca>
<07777266-f285-be52-0bff-752419352e85 AT t-online DOT de>
<CANH4o6NpCTV8JRohOy9bWs+uVVLAMp+TBxQOqEfuPqxvfsGFHA AT mail DOT gmail DOT com>
Organization: Inglis
In-Reply-To: <CANH4o6NpCTV8JRohOy9bWs+uVVLAMp+TBxQOqEfuPqxvfsGFHA@mail.gmail.com>
X-CMAE-Envelope: MS4xfOF3d7cbs9LBpEugszfI63lPsgBVJsqrLbZ8IWJ9k65zpdQAtWKeOeLZo6X6/eiGZUaw+g5d2s+q3LaELrjV6jw2PFRjFtAfHwBn/GFnHNVaAV6rkdcu
yHMSFYnN/x9KK8NNfmUHFnJN0lWArYeMrJeGKw6mDdsMoULkj6Kr3Iy99+/JRIfhraZ3+ZW+ytSSRkxtQWhupg8hSukFC7HYXrBtoj158PCn6gHyRvwbFi3S
X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW,
SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Brian Inglis via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Brian Inglis <Brian DOT Inglis AT Shaw DOT ca>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 38MC1pC8014448

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 AT cygwin DOT 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

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019