From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 79FA1384F6D5; Mon, 21 Nov 2022 18:51:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79FA1384F6D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669056666; bh=y1cXnF4/E3JbAtgoEQ2famwXVZMR2thayoOTnlfZspw=; h=From:To:Subject:Date:From; b=I5QNxTXCBSiyoLpkMy+pkVR98DazWRlg/d6IXSvak1iz30gx2zMJ99ffBrLMIXOhW l5pwrQ2qwQiK3Zq0Az5vb6jsQLo1vTGtEqrFAGP2ZyGo/kNJv+aGAwVo+BUX/NiP1v 9gABxj0VoCHjA/daB9MO8+XAGzz9OncQjC4qj7Qc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-4213] libstdc++: Check static assertions earlier in chrono::duration X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 94f7baf2194e2d20108c9d34d2766e6b14e25cef X-Git-Newrev: ed77dcb9be76e592b62449c75a5e751485514afd Message-Id: <20221121185106.79FA1384F6D5@sourceware.org> Date: Mon, 21 Nov 2022 18:51:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ed77dcb9be76e592b62449c75a5e751485514afd commit r13-4213-ged77dcb9be76e592b62449c75a5e751485514afd Author: Jonathan Wakely 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 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 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 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;