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.133.124]) by sourceware.org (Postfix) with ESMTPS id 052F23858281 for ; Thu, 22 Dec 2022 10:15:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 052F23858281 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=1671704142; 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=RgW8nBPPCHahloEX6S373NihBbOG9UrYa+uHkNAefOg=; b=BvkZfAx2IEShzlayptN/Bd/Z3Tlv/B1r9fpS6mC6kYFeWzxLDSQ7zr2wrXshrWJxAPnYzs ayNBUBpOBd+MpabkJEUr6QbxQxAqFa61pM8D8H2Iz7kvYi9uCtiAOUfA0pfFYPbocFuuGm 3fxaPaUpcywZ8UiMJnJ1PmHUhuZT/R8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-456-_DSbeEneNVG7XzV-t2vqPg-1; Thu, 22 Dec 2022 05:15:40 -0500 X-MC-Unique: _DSbeEneNVG7XzV-t2vqPg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D8D50857F44; Thu, 22 Dec 2022 10:15:39 +0000 (UTC) Received: from localhost (unknown [10.33.36.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 866AD2026D76; Thu, 22 Dec 2022 10:15:39 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add [[nodiscard]] in Date: Thu, 22 Dec 2022 10:15:38 +0000 Message-Id: <20221222101538.660256-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 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. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * include/std/chrono: Use nodiscard attribute. --- libstdc++-v3/include/std/chrono | 46 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 4c5fbfaeb83..33653f8efb1 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -128,11 +128,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using time_point = chrono::time_point; static constexpr bool is_steady = false; + [[nodiscard]] static time_point now() { return from_sys(system_clock::now()); } template + [[nodiscard]] static sys_time> to_sys(const utc_time<_Duration>& __t) { @@ -145,6 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] static utc_time> from_sys(const sys_time<_Duration>& __t) { @@ -171,11 +174,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr bool is_steady = false; // XXX true for CLOCK_TAI? // TODO move into lib, use CLOCK_TAI on linux, add extension point. + [[nodiscard]] static time_point now() { return from_utc(utc_clock::now()); } template + [[nodiscard]] static utc_time> to_utc(const tai_time<_Duration>& __t) { @@ -184,6 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] static tai_time> from_utc(const utc_time<_Duration>& __t) { @@ -208,11 +214,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr bool is_steady = false; // XXX // TODO move into lib, add extension point. + [[nodiscard]] static time_point now() { return from_utc(utc_clock::now()); } template + [[nodiscard]] static utc_time> to_utc(const gps_time<_Duration>& __t) { @@ -221,6 +229,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + [[nodiscard]] static gps_time> from_utc(const utc_time<_Duration>& __t) { @@ -394,6 +403,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Convert a time point to a different clock. template + [[nodiscard]] inline auto clock_cast(const time_point<_SourceClock, _Duration>& __t) requires __detail::__clock_convs<_DestClock, _SourceClock, _Duration> @@ -2620,6 +2630,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION leap_second(const leap_second&) = default; leap_second& operator=(const leap_second&) = default; + [[nodiscard]] constexpr sys_seconds date() const noexcept { @@ -2628,6 +2639,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return sys_seconds(-_M_s); } + [[nodiscard]] constexpr seconds value() const noexcept { @@ -2638,71 +2650,71 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // This can be defaulted because the database will never contain two // leap_second objects with the same date but different signs. - friend constexpr bool + [[nodiscard]] friend constexpr bool operator==(const leap_second&, const leap_second&) noexcept = default; - friend constexpr strong_ordering + [[nodiscard]] friend constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) noexcept { return __x.date() <=> __y.date(); } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) noexcept { return __x.date() == __y; } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) noexcept { return __x.date() < __y; } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) noexcept { return __x < __y.date(); } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) noexcept { return __y < __x.date(); } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) noexcept { return __y.date() < __x; } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator<=(const leap_second& __x, - const sys_time<_Duration>& __y) noexcept + const sys_time<_Duration>& __y) noexcept { return !(__y < __x.date()); } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator<=(const sys_time<_Duration>& __x, - const leap_second& __y) noexcept + const leap_second& __y) noexcept { return !(__y.date() < __x); } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator>=(const leap_second& __x, - const sys_time<_Duration>& __y) noexcept + const sys_time<_Duration>& __y) noexcept { return !(__x.date() < __y); } template - friend constexpr bool + [[nodiscard]] friend constexpr bool operator>=(const sys_time<_Duration>& __x, - const leap_second& __y) noexcept + const leap_second& __y) noexcept { return !(__x < __y.date()); } template _Duration> - friend constexpr auto + [[nodiscard]] friend constexpr auto operator<=>(const leap_second& __x, - const sys_time<_Duration>& __y) noexcept + const sys_time<_Duration>& __y) noexcept { return __x.date() <=> __y; } private: -- 2.38.1