From patchwork Tue Jun 11 12:07:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1946289 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=RSdGpxBA; 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 4Vz6rJ25VSz20Py for ; Tue, 11 Jun 2024 22:08:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D50A385DDF1 for ; Tue, 11 Jun 2024 12:07:58 +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 ESMTPS id 27D373858C48 for ; Tue, 11 Jun 2024 12:07:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27D373858C48 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 27D373858C48 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=1718107654; cv=none; b=qzSZnypgqA2EDLSWkRS3/W4y0H+ANyibV9IXfXke1SpxAEvvIGi4WLPHt0zA9EQcGLDR4TOQbqSLOIFa2zVBa3fqlvfc10lHt/XabRUrBQFbmuAHC6z3A6BlulxcetdsbMKN3XM+8Kz1wc+SNJP5w3UmxYAX4H03omvt38hFSZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718107654; c=relaxed/simple; bh=CkCggHCN8mvLdZJS8rqmjCuArz7aFPlMqa2ahxKCnzw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=e6UA29DxbdQ+JM1BsFU/F+2DAMSxGwE86dFHFJ2HEHADs+5XTLsomHIOoJlV5JqHF28jHe3f4Sxw0D7FrQExfaI7XwJLXqAzfPUddguWuFcEhNksptfI+91SndvRaIJCo8iDXwZzy6tBzQKId44OQol8uXK+Jo678i/3v5ONM2g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718107651; 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=XbWNrJHK9k9Onn+a6Y4vTbHkVFWltt7SQGtOrV8a04A=; b=RSdGpxBAqNXOGU6ccKqKwYwOBzVZ7NulefKSEosYGavkY2OvtVfsuZ5GWVRm2NjaX94IIz tyKky6E6XapAfUGXSYBUHSVYJaOXUeX+29l86rI8LFh8LZA4zyLu48rvqBQShf8ctEj9Xy wegyARN+4Oz7JG7Qq7crsxvFeNH5kK0= 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-627-MHSmMpGNORWA4CIoyknFwg-1; Tue, 11 Jun 2024 08:07:30 -0400 X-MC-Unique: MHSmMpGNORWA4CIoyknFwg-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 57A561955F0F; Tue, 11 Jun 2024 12:07:28 +0000 (UTC) Received: from localhost (unknown [10.39.192.128]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5312330000C4; Tue, 11 Jun 2024 12:07:26 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add test for chrono::leap_seconds ostream insertion Date: Tue, 11 Jun 2024 13:07:11 +0100 Message-ID: <20240611120725.682088-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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 -- Also add a comment to the three-way comparison oeprator for chrono::leap_seconds, noting the deviation from the spec (which is functionally equivalent). What we implement is the originally proposed resolution to LWG 3383, which should compile slightly more efficiently than the final accepted resolution. libstdc++-v3/ChangeLog: * include/std/chrono (leap_seconds): Add comment. * testsuite/std/time/leap_seconds/io.cc: New test. --- libstdc++-v3/include/std/chrono | 2 + .../testsuite/std/time/leap_seconds/io.cc | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 libstdc++-v3/testsuite/std/time/leap_seconds/io.cc diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index b0aadf83b03..7ffa5360728 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -2925,6 +2925,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const leap_second& __y) noexcept { return !(__x < __y.date()); } + // This is a simplified form of the constraint specified in the standard, + // three_way_comparable_with>. template _Duration> [[nodiscard]] friend constexpr auto operator<=>(const leap_second& __x, diff --git a/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc b/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc new file mode 100644 index 00000000000..511fafdd1a0 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc @@ -0,0 +1,56 @@ +// { dg-do run { target c++20 } } +// { dg-require-effective-target tzdb } +// { dg-require-effective-target cxx11_abi } + +#include +#include +#include +#include + +void +test_output() +{ + using namespace std::chrono; + + std::ostringstream out; + out << '\n'; + + for (auto& l : get_tzdb().leap_seconds) + if (l <= sys_days{2018y/March/17d}) + out << l.date() << ": " << l.value() << '\n'; + + VERIFY( out.str() == R"( +1972-07-01 00:00:00: 1s +1973-01-01 00:00:00: 1s +1974-01-01 00:00:00: 1s +1975-01-01 00:00:00: 1s +1976-01-01 00:00:00: 1s +1977-01-01 00:00:00: 1s +1978-01-01 00:00:00: 1s +1979-01-01 00:00:00: 1s +1980-01-01 00:00:00: 1s +1981-07-01 00:00:00: 1s +1982-07-01 00:00:00: 1s +1983-07-01 00:00:00: 1s +1985-07-01 00:00:00: 1s +1988-01-01 00:00:00: 1s +1990-01-01 00:00:00: 1s +1991-01-01 00:00:00: 1s +1992-07-01 00:00:00: 1s +1993-07-01 00:00:00: 1s +1994-07-01 00:00:00: 1s +1996-01-01 00:00:00: 1s +1997-07-01 00:00:00: 1s +1999-01-01 00:00:00: 1s +2006-01-01 00:00:00: 1s +2009-01-01 00:00:00: 1s +2012-07-01 00:00:00: 1s +2015-07-01 00:00:00: 1s +2017-01-01 00:00:00: 1s +)" ); +} + +int main() +{ + test_output(); +}