From patchwork Mon Jul 29 17:56:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1966182 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=R0OAsfuF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4WXmMT6qKxz20FY for ; Tue, 30 Jul 2024 03:59:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 364A8385DDDB for ; Mon, 29 Jul 2024 17:59:16 +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.129.124]) by sourceware.org (Postfix) with ESMTP id 9F9A13858420 for ; Mon, 29 Jul 2024 17:58:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F9A13858420 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 9F9A13858420 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722275927; cv=none; b=ggCHj+8viaL/w9vXL182pSOsJiGP0xam4ioX4gjkEIZw9PVSmBT88Z6SDdjrfeuDxk82w9F+nZeYytNwmmyFUsBGLah94TZMoq0HvVDHAT900E8fR6w8dfKX2VA5Unyun+pM/kcR30kr5OPvD78SC+xjVrdzTC8Lhf2rbWgQzMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722275927; c=relaxed/simple; bh=rkrvEbHf+TwIfAkHbudH7D/izMdu74FymGEjagGcSrM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=O4EQi2QBVmBtDbmBYePT1Ivr7zQhDd4erCZnUdc7ZoUyncc/RR1H0xjWH4BySePHJwsskErvHJNaanPR2ckTDLa7ZaGEitrOJFDwYG9EJE24m5eE5TSU0lihJ88Y+TGVtcVak2U3hol/K025q0Q19oU4FDncKfAbad2+3vJxGtE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722275925; 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: in-reply-to:in-reply-to:references:references; bh=laC1Hih+iiTbp2qGO1/Sruf6VgkveBBrM90mxOAWylI=; b=R0OAsfuFuDVnbinbhkwhOfy4qbMTi8KFbhDcjOS5C9l/RpzIV/33CSgPoyZeziBuvuSvMN 0cPu0ON3QYDVDO76F/0h+ksnqbLznNAxbxDyaUjhtDB8Z6ZJWKBoiM7YQa8zRGlgBGPOkU h9IExVF07NIbd6MK0P6hwVJ4S6e5wO8= Received: from mx-prod-mc-03.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-209-pYVelIRCOmOjG789hsQDuw-1; Mon, 29 Jul 2024 13:58:42 -0400 X-MC-Unique: pYVelIRCOmOjG789hsQDuw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 12B8219560BA; Mon, 29 Jul 2024 17:58:41 +0000 (UTC) Received: from localhost (unknown [10.42.28.14]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 83DBD19560AA; Mon, 29 Jul 2024 17:58:39 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Fix formatter for low-resolution chrono::zoned_time (LWG 4124) Date: Mon, 29 Jul 2024 18:56:07 +0100 Message-ID: <20240729175835.825721-2-jwakely@redhat.com> In-Reply-To: <20240729175835.825721-1-jwakely@redhat.com> References: <20240729175835.825721-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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. -- >8 -- This implements the proposed resolution of LWG 4124, so that low-resolution chrono::zoned_time objects can be formatted. The formatter for zoned_time needs to account for get_local_time returning local_time> not local_time. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__local_time_fmt_for): New alias template. (formatter>): Use __local_time_fmt_for. * testsuite/std/time/zoned_time/io.cc: Check zoned_time can be formatted. --- libstdc++-v3/include/bits/chrono_io.h | 12 +++++++++--- libstdc++-v3/testsuite/std/time/zoned_time/io.cc | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index e7e7deb2cde..d8a4a121113 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -164,6 +164,12 @@ namespace __detail const string* _M_abbrev; const seconds* _M_offset_sec; }; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4124. Cannot format zoned_time with resolution coarser than seconds + template + using __local_time_fmt_for + = __local_time_fmt>; } /// @endcond @@ -2137,15 +2143,15 @@ namespace __format #if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI template struct formatter, _CharT> - : formatter, _CharT> + : formatter, _CharT> { template typename _FormatContext::iterator format(const chrono::zoned_time<_Duration, _TimeZonePtr>& __tp, _FormatContext& __ctx) const { - using chrono::__detail::__local_time_fmt; - using _Base = formatter<__local_time_fmt<_Duration>, _CharT>; + using _Ltf = chrono::__detail::__local_time_fmt_for<_Duration>; + using _Base = formatter<_Ltf, _CharT>; const chrono::sys_info __info = __tp.get_info(); const auto __lf = chrono::local_time_format(__tp.get_local_time(), &__info.abbrev, diff --git a/libstdc++-v3/testsuite/std/time/zoned_time/io.cc b/libstdc++-v3/testsuite/std/time/zoned_time/io.cc index ee3b9edba81..c113eea6d3f 100644 --- a/libstdc++-v3/testsuite/std/time/zoned_time/io.cc +++ b/libstdc++-v3/testsuite/std/time/zoned_time/io.cc @@ -66,6 +66,10 @@ test_format() ws = std::format(L"{:+^34}", zoned_time(zone, t)); VERIFY( ws == L"++2022-12-19 12:26:25.708000 EST++" ); #endif + + // LWG 4124. Cannot format zoned_time with resolution coarser than seconds + s = std::format("{}", zoned_time(zone, time_point_cast(t))); + VERIFY( s == "2022-12-19 12:26:00 EST" ); } int main()