public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5175] libstdc++: Fix narrowing conversion in std/time/clock/utc/io.cc
@ 2023-01-15 12:44 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-01-15 12:44 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:4dc4584b6079ac801ed5f0c79d335891821dbb3b

commit r13-5175-g4dc4584b6079ac801ed5f0c79d335891821dbb3b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sun Jan 15 12:38:31 2023 +0000

    libstdc++: Fix narrowing conversion in std/time/clock/utc/io.cc
    
    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.

Diff:
---
 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),

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-15 12:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-15 12:44 [gcc r13-5175] libstdc++: Fix narrowing conversion in std/time/clock/utc/io.cc Jonathan Wakely

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).