public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Filip Kastl <pheeck@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/pheeck/heads/sccp)] libstdc++: Check static assertions earlier in chrono::duration Date: Wed, 15 Feb 2023 10:17:33 +0000 (GMT) [thread overview] Message-ID: <20230215101733.C7EE73858284@sourceware.org> (raw) https://gcc.gnu.org/g:9563a144accfeeb419abbe0f0bb78b5c2a957a08 commit 9563a144accfeeb419abbe0f0bb78b5c2a957a08 Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Nov 21 11:52:34 2022 +0000 libstdc++: Check static assertions earlier in chrono::duration This ensures that we fail a static assertion before giving any other errors. Instantiating chrono::duration<int, chrono::seconds> will now print this before the other errors caused by it: error: static assertion failed: period must be a specialization of ratio libstdc++-v3/ChangeLog: * include/bits/chrono.h (duration): Check preconditions on template arguments before using them. Diff: --- libstdc++-v3/include/bits/chrono.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h index 05987ca09df..cabf61264d8 100644 --- a/libstdc++-v3/include/bits/chrono.h +++ b/libstdc++-v3/include/bits/chrono.h @@ -433,6 +433,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Rep, typename _Period> struct duration { + static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); + static_assert(__is_ratio<_Period>::value, + "period must be a specialization of ratio"); + static_assert(_Period::num > 0, "period must be positive"); + private: template<typename _Rep2> using __is_float = treat_as_floating_point<_Rep2>; @@ -478,11 +483,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using rep = _Rep; using period = typename _Period::type; - static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); - static_assert(__is_ratio<_Period>::value, - "period must be a specialization of ratio"); - static_assert(_Period::num > 0, "period must be positive"); - // 20.11.5.1 construction / copy / destroy constexpr duration() = default;
reply other threads:[~2023-02-15 10:17 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=20230215101733.C7EE73858284@sourceware.org \ --to=pheeck@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).