From patchwork Fri Oct 11 14:52:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1996174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K+msM7q9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XQ8mN6tnYz1xtv for ; Sat, 12 Oct 2024 01:54:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9D6D3858C2B for ; Fri, 11 Oct 2024 14:54:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 1A618385843F for ; Fri, 11 Oct 2024 14:53:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A618385843F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1A618385843F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728658389; cv=none; b=FsjwlJqjJSjO811xSwydzSQafCRif/6ulibX/hJirzK4XltgDx/vQ27v+wVXkgFs8K+Ww8mH1RRGWulby/sPDkEY3Xll3ejasPE30ex17Dtv7GfwX0Ro4UhYlux6lUcqYuaevYscKOIbpeMA98/sVzOTP6al7nKqGCN30S4u0Ew= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728658389; c=relaxed/simple; bh=m9ivWp9zmtY2j9shMGfTROG2ISTL2PF6Y7K7Zdq8rug=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=az9l6RLIxI+Nb8x6exfwLj5xE/saVyDXDI7wg/9NlcdoZiGR7wX1isdy6SsfCAnVJlUKHfWM8bpfH1yAY4AXUL9lqFGL1xLuRXCcNwG1M12oozS3WWA9+Nv8Putth+6HPH5EKB+TWah3qkmftQLePKgmhKf7IoNfaeZvAa5lHP4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728658386; 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=yRELL2aA5IgJh8TTjv/IUH+b5R8aySqKkWZLEY+GXq4=; b=K+msM7q9PzV9zRpfs70eD4BUn2b68hG/DF9EDNTHk+g+CYAR4qkC7He0sm5uo5nMz11gz6 bdSxJ1ztWHNknRwVvkvsArwuaP/rfs2kSBavzz5u03gMPwrpRX39XEwETvxaKxGngmUUWp Q2KVdXRbjkeM1D+wX/QbyudhND66qQM= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-0pmcquI4PVG_GVWytqRncA-1; Fri, 11 Oct 2024 10:53:03 -0400 X-MC-Unique: 0pmcquI4PVG_GVWytqRncA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D1C91195419B; Fri, 11 Oct 2024 14:53:02 +0000 (UTC) Received: from localhost (unknown [10.42.28.27]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 642AC19560A2; Fri, 11 Oct 2024 14:53:01 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix localized %c formatting for [PR117085] Date: Fri, 11 Oct 2024 15:52:41 +0100 Message-ID: <20241011145300.1322712-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- When formatting a time point with %c we call std::vformat_to using the formatting locale's D_T_FMT string, but we weren't adding the L option to the format string. This meant we always interpreted D_T_FMT in the C locale, instead of using the formatting locale as obviously intended when %c is used. libstdc++-v3/ChangeLog: PR libstdc++/117085 * include/bits/chrono_io.h (__formatter_chrono::_M_c): Add L option to format string. * testsuite/std/time/format.cc: Move to... * testsuite/std/time/format/format.cc: ...here. * testsuite/std/time/format_localized.cc: Move to... * testsuite/std/time/format/localized.cc: ...here. * testsuite/std/time/format/pr117085.cc: New test. --- libstdc++-v3/include/bits/chrono_io.h | 14 ++++++++------ .../testsuite/std/time/{ => format}/format.cc | 0 .../localized.cc} | 0 .../testsuite/std/time/format/pr117085.cc | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) rename libstdc++-v3/testsuite/std/time/{ => format}/format.cc (100%) rename libstdc++-v3/testsuite/std/time/{format_localized.cc => format/localized.cc} (100%) create mode 100644 libstdc++-v3/testsuite/std/time/format/pr117085.cc diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index 652e88ffe3a..8c026586d4c 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -893,17 +893,19 @@ namespace __format // %c Locale's date and time representation. // %Ec Locale's alternate date and time representation. + basic_string<_CharT> __fmt; auto __t = _S_floor_seconds(__tt); locale __loc = _M_locale(__ctx); const auto& __tp = use_facet<__timepunct<_CharT>>(__loc); const _CharT* __formats[2]; __tp._M_date_time_formats(__formats); - const _CharT* __rep = __formats[__mod]; - if (!*__rep) [[unlikely]] - __rep = _GLIBCXX_WIDEN("%a %b %e %T %Y"); - basic_string<_CharT> __fmt(_S_empty_spec); - __fmt.insert(1u, 1u, _S_colon); - __fmt.insert(2u, __rep); + if (*__formats[__mod]) [[likely]] + { + __fmt = _GLIBCXX_WIDEN("{:L}"); + __fmt.insert(3u, __formats[__mod]); + } + else + __fmt = _GLIBCXX_WIDEN("{:L%a %b %e %T %Y}"); return std::vformat_to(std::move(__out), __loc, __fmt, std::make_format_args<_FormatContext>(__t)); } diff --git a/libstdc++-v3/testsuite/std/time/format.cc b/libstdc++-v3/testsuite/std/time/format/format.cc similarity index 100% rename from libstdc++-v3/testsuite/std/time/format.cc rename to libstdc++-v3/testsuite/std/time/format/format.cc diff --git a/libstdc++-v3/testsuite/std/time/format_localized.cc b/libstdc++-v3/testsuite/std/time/format/localized.cc similarity index 100% rename from libstdc++-v3/testsuite/std/time/format_localized.cc rename to libstdc++-v3/testsuite/std/time/format/localized.cc diff --git a/libstdc++-v3/testsuite/std/time/format/pr117085.cc b/libstdc++-v3/testsuite/std/time/format/pr117085.cc new file mode 100644 index 00000000000..99ef8389995 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/format/pr117085.cc @@ -0,0 +1,19 @@ +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-1" } + +#include +#include +#include + +void +test_c() +{ + std::locale::global(std::locale(ISO_8859(1,fr_FR))); + auto s = std::format("{:L%c}", std::chrono::sys_seconds()); + VERIFY( ! s.starts_with("Thu") ); +} + +int main() +{ + test_c(); +}