X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3859C385772F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1695362242; bh=F4alOrWKXnx+iGE99GD7a3V1STJGAc55QtVB2nKkYhY=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FkOe6fUPDZpYnRD0qag0fbURZa1qsDXuWs/nkYOkXZtJeLtMbHOzA1mxRPHHSy9pw 71nA5Fn6sE+dY4eFL5Un7Hv7mue03bwCU4XPJwA132DP18tQXny5/zxwYC3gK+aFlo /n+vkmFFJ+ApZ22SzMZfvL5JetnzJ01LmvFYwHzE= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94FB43858C53 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695362201; x=1695967001; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HOCU9ECe9QlvlWIMtwRyKtv2RexvwIz2DwQAjangn6I=; b=KOKVZr2rkAOlDr3qb3bEFWKZpFuW4wwVsvRsWw/ru5HEpnj0c6K9hbKgCMgJdIYU2L GVvNHGrOYfHEQwRzC0swUf5JMXzWoIxdaE+USCwRFtMg2K1sC52hmZh9YwdbgiIAEiSh CcUzhKF7+Op9g4z4WujHjp3Fpp3zQykvhef3/xKv6lH4MnEbLylgnV8jCwBqLHzvLRNs 3vlBJYioaOJvs/DsY+/2Qx2G/2HVviOjqwJo3VH7vmRK4C8gp9xIwa+tKLRdapm1Z1a8 I09sEOmpBJjmMAM0gnlgzp+hkIZ9tqFAVRMnf+RpnJnoYHtDVDm75hLLE0/7cO297IRU imGg== X-Gm-Message-State: AOJu0YzFlUZEbg4W9G9hjBtbPoOwhnZzHR0DOl7Jcz0ftzmw9BE7Yl4c NQWRgikVeMV8YoyLg1nkHazUsCjeVb4FpBrYwRfnHWYf X-Google-Smtp-Source: AGHT+IEbNLU4rZhKg255Ao9dltEBDWPBxgHZtCEGugTkMGIQmq8yJPwbJ7MEnEPyYf9vZvC45n43Q641aFLw13MGfjs= X-Received: by 2002:a05:6870:390e:b0:1bb:f801:411a with SMTP id b14-20020a056870390e00b001bbf801411amr8116996oap.11.1695362201666; Thu, 21 Sep 2023 22:56:41 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <07777266-f285-be52-0bff-752419352e85@t-online.de> Date: Fri, 22 Sep 2023 07:56:30 +0200 Message-ID: Subject: Re: std::runtime_error on std::locale("") To: cygwin AT cygwin DOT com X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 List-Archive: List-Post: List-Help: List-Subscribe: , From: Martin Wege via Cygwin Reply-To: Martin Wege Content-Type: text/plain; charset="utf-8" Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 38M5vMtU027307 On Thu, Sep 21, 2023 at 9:07 PM Christian Franke via Cygwin 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 > >>> 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 > > #include > > > > 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. What does bash -c 'locale -a' print on your system? Thanks, Martin -- 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