From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C398E3858C53; Wed, 10 Jan 2024 22:52:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C398E3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704927134; bh=aapGMZN+rWSXQUb+vFUMJ/erZdHiGj1DiPzmDRIeJ3k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Rqb2iqcZIHCWThA0osk/ieiWcUIA5AWSShjgf1acy/pXNWH8cXZueAU3Idywjf8XX P0VNHiWnAmeIOBVmXuYmtnEgRgU2LGFgEdODgSTtqSZv/hHuTdnKRLdEkKl1PWI6KT eX98e6qL/s79vKBCMb+lWKkGA1YJCZHx9i8f3Ims= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109162] C++23 improvements to std::format Date: Wed, 10 Jan 2024 22:52:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109162 --- Comment #4 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #3) > (In reply to Jonathan Wakely from comment #0) > > https://wg21.link/P2419R2 localized chrono formatting (also p2372r3) >=20 > I think this this requires using nl_langinfo_l(CODESET, loc) to find out = if > the locale uses UTF-8, and then use iconv to convert to UTF-8 if it doesn= 't. > But I'm not sure how we do that for an arbitrary std::locale which doesn't > have an associated C locale, and we can't get its locale_t identifier any= way. I remain confused about how to implement this. We could use newlocale(loc.name()) to try to open a C locale from the C++ locale's name,= and if that works use nl_langinfo_l to get the locale's encoding, then use icon= v to convert to UTF-8. Libc++ doesn't implement this yet. {fmt} does ... but it seems broken. It u= ses std::codecvt to convert the locale's encoding to UTF-32 and then converts that to UTF-8. But that's wrong. That codecvt specialization converts between UTF-8 and UTF-32, it's locale-independent. = So the example in P2419 fails with a format_error exception when I run it: #include #include #include #include #include #include int main() { std::locale::global(std::locale("ru_UA.koi8u")); std::string s =3D fmt::format("=D0=94=D0=B5=D0=BD=D1=8C =D0=BD=D0=B5=D0= =B4=D0=B5=D0=BB=D0=B8: {:L}", std::chrono::Monday); std::cout << s << '\n'; } terminate called after throwing an instance of 'fmt::v9::format_error' what(): failed to format time Aborted (core dumped)=