From owner-freebsd-bugs@freebsd.org Tue Dec 8 19:18:40 2020 Return-Path: Delivered-To: freebsd-bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 743574A9C4C for ; Tue, 8 Dec 2020 19:18:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4Cr92S2ZMgz4p41 for ; Tue, 8 Dec 2020 19:18:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id 566A24A9C4B; Tue, 8 Dec 2020 19:18:40 +0000 (UTC) Delivered-To: bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 550FE4A9E7C for ; Tue, 8 Dec 2020 19:18:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cr92S1ms1z4nxj for ; Tue, 8 Dec 2020 19:18:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2ED1319616 for ; Tue, 8 Dec 2020 19:18:40 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 0B8JIeuW022715 for ; Tue, 8 Dec 2020 19:18:40 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 0B8JIe9V022714 for bugs@FreeBSD.org; Tue, 8 Dec 2020 19:18:40 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 251674] libc++: std::wcout does not use global locale set via setlocale() Date: Tue, 08 Dec 2020 19:18:40 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: dim@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Dec 2020 19:18:40 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D251674 --- Comment #11 from Dimitry Andric --- (In reply to Yuri Pankov from comment #9) > So libstdc++'s wcout being affected by setlocale() call is just an > implementation choice, the one that libc++ didn't make? Apparently, although that documentation link from libstdc++ that I pasted doesn't really tell anything about it, except maybe the part: > Locale initialization: at what point does _S_classic, _S_global get > initialized? Can named locales assume this initialization has already tak= en > place?=20 but it seems this doc article is very old. Looking at libstdc++'s implementation, it appears they initialize a default locale() object here: https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dblob;f=3Dlibstdc%2B%2B-v3/src/c%2B= %2B98/ios_locale.cc#l44 // Called only by basic_ios<>::init. void ios_base::_M_init() throw() { // NB: May be called more than once _M_precision =3D 6; _M_width =3D 0; _M_flags =3D skipws | dec; _M_ios_locale =3D locale(); } This default locale() object is constructed in https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dblob;f=3Dlibstdc%2B%2B-v3/src/c%2B= %2B98/locale_init.cc, but it seems like a separate copy of a C-like locale by default, e.g it has: void locale::_S_initialize_once() throw() { // 2 references. // One reference for _S_classic, one for _S_global _S_classic =3D new (&c_locale_impl) _Impl(2); _S_global =3D _S_classic; new (&c_locale) locale(_S_classic); } and the _Impl constructor is: // Construct "C" _Impl. locale::_Impl:: _Impl(size_t __refs) throw() : _M_refcount(__refs), _M_facets(0), _M_facets_size(num_facets), _M_caches(0), _M_names(0) { _M_facets =3D new (&facet_vec) const facet*[_M_facets_size](); _M_caches =3D new (&cache_vec) const facet*[_M_facets_size](); // Name the categories. _M_names =3D new (&name_vec) char*[_S_categories_size](); _M_names[0] =3D new (&name_c[0]) char[2]; std::memcpy(_M_names[0], locale::facet::_S_get_c_name(), 2); // This is needed as presently the C++ version of "C" locales // !=3D data in the underlying locale model for __timepunct, // numpunct, and moneypunct. Also, the "C" locales must be // constructed in a way such that they are pre-allocated. // NB: Set locale::facets(ref) count to one so that each individual // facet is not destroyed when the locale (and thus locale::_Impl) is // destroyed. _M_init_facet(new (&ctype_c) std::ctype(0, false, 1)); _M_init_facet(new (&codecvt_c) codecvt(1)); ... much more of this ... } So I think what you're seeing with libstdc++ is intentional, in the sense t= hat they have a default locale which is sort-of the same as the default C locale (or even C.UTF-8). The only call to setlocale() in that .cc file is when you call std::locale::global(), as indicated in the docs. --=20 You are receiving this mail because: You are the assignee for the bug.=