From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A53F73858D32 for ; Sun, 15 Jan 2023 12:45:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A53F73858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673786747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5wB5o1ciRrkHcwQa0hd9EbO0bs9tKH+WlMRHY1phXdc=; b=EHy/P4c9DB1PHQmZ6qVaTNyoCDNU9ppmuH7pOTlDPwCSNHfLRCslVTJXsH47s+b6JWB6E8 bG+l8v5VITicH5fy7EvJpB0roH1+Q3BI6sDtUDyIYirWLerpOK07FKTTEVzl16kskrmwqn Lu3fEJZBefNwWy2rKIxKQxsjlibO7SY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-61-UcV53mTxMrSW_d9dvYwTsw-1; Sun, 15 Jan 2023 07:45:46 -0500 X-MC-Unique: UcV53mTxMrSW_d9dvYwTsw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE75D3804062; Sun, 15 Jan 2023 12:45:45 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 870BB40C2064; Sun, 15 Jan 2023 12:45:45 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20230115124544.1338953-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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::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>(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