public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-4840] libstdc++: Add [[nodiscard]] in <chrono> Date: Thu, 22 Dec 2022 10:15:05 +0000 (GMT) [thread overview] Message-ID: <20221222101505.195943858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:ec8f914f572ce45dbf5743c801c6a101e9a785c7 commit r13-4840-gec8f914f572ce45dbf5743c801c6a101e9a785c7 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Dec 22 00:19:45 2022 +0000 libstdc++: Add [[nodiscard]] in <chrono> libstdc++-v3/ChangeLog: * include/std/chrono: Use nodiscard attribute. Diff: --- 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<utc_clock>; static constexpr bool is_steady = false; + [[nodiscard]] static time_point now() { return from_sys(system_clock::now()); } template<typename _Duration> + [[nodiscard]] static sys_time<common_type_t<_Duration, seconds>> to_sys(const utc_time<_Duration>& __t) { @@ -145,6 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Duration> + [[nodiscard]] static utc_time<common_type_t<_Duration, seconds>> 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<typename _Duration> + [[nodiscard]] static utc_time<common_type_t<_Duration, seconds>> to_utc(const tai_time<_Duration>& __t) { @@ -184,6 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Duration> + [[nodiscard]] static tai_time<common_type_t<_Duration, seconds>> 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<typename _Duration> + [[nodiscard]] static utc_time<common_type_t<_Duration, seconds>> to_utc(const gps_time<_Duration>& __t) { @@ -221,6 +229,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Duration> + [[nodiscard]] static gps_time<common_type_t<_Duration, seconds>> from_utc(const utc_time<_Duration>& __t) { @@ -394,6 +403,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Convert a time point to a different clock. template<typename _DestClock, typename _SourceClock, typename _Duration> + [[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<typename _Duration> - friend constexpr bool + [[nodiscard]] friend constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) noexcept { return __x.date() == __y; } template<typename _Duration> - friend constexpr bool + [[nodiscard]] friend constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) noexcept { return __x.date() < __y; } template<typename _Duration> - friend constexpr bool + [[nodiscard]] friend constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) noexcept { return __x < __y.date(); } template<typename _Duration> - friend constexpr bool + [[nodiscard]] friend constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) noexcept { return __y < __x.date(); } template<typename _Duration> - friend constexpr bool + [[nodiscard]] friend constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) noexcept { return __y.date() < __x; } template<typename _Duration> - 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<typename _Duration> - 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<typename _Duration> - 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<typename _Duration> - 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<three_way_comparable_with<seconds> _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:
reply other threads:[~2022-12-22 10:15 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221222101505.195943858D1E@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).