From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC27F3861893; Mon, 13 May 2024 07:14:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC27F3861893 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715584451; bh=zFUixuCU64Wg871IPeDmenEEXKIVXU+29Cr5Yv1LdVA=; h=From:To:Subject:Date:From; b=gpMPXNEdjtW+6JCFio3IQCIPYaYvn2JExFlKUDBHerKuGHHh/D0gebmYB3ktgYzNN rJXM6AbZlgwTCJTyl50NtDA5+cFhbG4XE8b8YH0VLkY3xWEKvvz07NQTuFCSHxK8ng GTNB6EmlPbHIGuWHAFHzHvZSOd+RjQrnrP4aBLms= From: "lcarreon at bigpond dot net.au" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/115064] New: Possible problem with money_put Date: Mon, 13 May 2024 07:14:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lcarreon at bigpond dot net.au X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D115064 Bug ID: 115064 Summary: Possible problem with money_put Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lcarreon at bigpond dot net.au Target Milestone: --- I have been experimenting with std::money_put and discovered the following: #include #include #include #include #include int main() { std::locale loc{std::locale{"de_DE.utf8"}}; std::cout.imbue(loc); auto money =3D 123456789.0L; { const auto& money_put =3D std::use_facet>(std::cout.getloc()); std::cout << "\"" << std::showbase << std::setw(20) << std::right; money_put.put(std::cout, false, std::cout, '*', money); std::cout << "\"" << std::endl; } { std::ostringstream str; str.imbue(loc); const auto& money_put =3D std::use_facet>(str.getl= oc()); str << std::showbase << std::setw(20) << std::right; money_put.put(str, false, str, '*', money); str << std::endl; for (const auto& ch : str.str()) { std::cout << std::format("{:02x} ", ch); } std::cout << std::endl; } return 0; } I compiled the above program using g++ 14.0.1 using c++20 mode. When I exec= ute the program on a terminal whose LANG is set to en_AU.utf8, I get the follow= ing result: "****1.234.567,89*=E2=82=AC" 2a 2a 2a 2a 31 2e 32 33 34 2e 35 36 37 2c 38 39 2a e2 82 ac 0a The first line above is the problematic one because it shows only 18 charac= ters inside the double quotes instead of 20. The second line above explains why= .=20 The euro symbol is made up of three octets which is upsetting std::setw(20). I revised the above program using wchar_t and std::wcout as follows: #include #include #include #include #include int main() { std::locale loc{std::locale{"de_DE.utf8"}}; std::wcout.imbue(loc); auto money =3D 123456789.0L; { const auto& money_put =3D std::use_facet>(std::wcout.getloc()); std::wcout << L"\"" << std::showbase << std::setw(20) << std::right; money_put.put(std::wcout, false, std::wcout, L'*', money); std::wcout << L"\"" << std::endl; } { std::wostringstream str; str.imbue(loc); const auto& money_put =3D std::use_facet>(str.getloc()); str << std::showbase << std::setw(20) << std::right; money_put.put(str, false, str, L'*', money); str << std::endl; for (const auto& ch : str.str()) { std::wcout << std::format(L"{:02x} ", static_cast(ch)); } std::wcout << std::endl; } return 0; } Executing the above program on the same terminal, I get the following: "******1.234.567,89*EUR" 2a 2a 2a 2a 2a 2a 31 2e 32 33 34 2e 35 36 37 2c 38 39 2a 20ac 0a The first line above now has 22 characters instead of 20. The second line above shows what characters were sent to the terminal. It seems the euro symbol "20ac" is displayed by the terminal as "EUR" instead of the single g= lyph "=E2=82=AC". I understand that the terminal is set for UTF-8, thus the correct display of the euro symbol in char mode. But why display "EUR" in wchar_t mode?=