public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix narrowing conversion in std/time/clock/utc/io.cc
Date: Sun, 15 Jan 2023 12:45:44 +0000	[thread overview]
Message-ID: <20230115124544.1338953-1-jwakely@redhat.com> (raw)

Tested x86_64-linux, and verified with -fsigned-char -fshort-wchar
(which makes the underlying type of wchar_t be unsigned short).

Nightstrike also tested on mingw-w64.

Pushed to trunk.

-- >8 --

For a port with signed char and unsigned wchar_t initializing a wchar_t
array with a char is a narrowing conversion. The code is wrong for
assuming that (int)'a' == (int)L'a' anyway, so fix it properly by using
ctype<wchar_t>::widen(char).

libstdc++-v3/ChangeLog:

	* testsuite/std/time/clock/utc/io.cc: Use ctype to widen char.
---
 libstdc++-v3/testsuite/std/time/clock/utc/io.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/std/time/clock/utc/io.cc b/libstdc++-v3/testsuite/std/time/clock/utc/io.cc
index b327c7f50c7..933cba65f44 100644
--- a/libstdc++-v3/testsuite/std/time/clock/utc/io.cc
+++ b/libstdc++-v3/testsuite/std/time/clock/utc/io.cc
@@ -46,6 +46,7 @@ test_format()
 
   std::ostringstream ss;
   std::wostringstream wss;
+  const auto& ct = std::use_facet<std::ctype<wchar_t>>(wss.getloc());
 
   for (char c : specs)
   {
@@ -68,7 +69,7 @@ test_format()
 		    "required by the chrono-specs") != s.npos);
     }
 
-    wchar_t wfmt[] = { L'{', L':', L'%', c, L'}' };
+    wchar_t wfmt[] = { L'{', L':', L'%', ct.widen(c), L'}' };
     try
     {
       wss << std::vformat(std::wstring_view(wfmt, 5),
-- 
2.39.0


                 reply	other threads:[~2023-01-15 12:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230115124544.1338953-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).