From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7879) id C7EE73858284; Wed, 15 Feb 2023 10:17:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7EE73858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676456253; bh=mW7Nd4n4DInBMo0o5wYshaYZjN52p2U1lUTcGPR7ILs=; h=From:To:Subject:Date:From; b=c2Uei62teXomLZIUOR4DVUfJpN9DXcmFj2yDh62gE9aWEssoWs6wJQnMoF00z88fV UzrM9aBue95WfcNZUrXTvg5kV3Z3XGKWV8jZmUtK2QZ79pkXjDTfAL3xkczN1DcsNc +3LZrt11z4PX0uJ7T0t3vYFWqqTMXtEQWrDwDYHQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Filip Kastl 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 X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/users/pheeck/heads/sccp X-Git-Oldrev: da0a482432d71db10a247a352bababe4f131d266 X-Git-Newrev: 9563a144accfeeb419abbe0f0bb78b5c2a957a08 Message-Id: <20230215101733.C7EE73858284@sourceware.org> Date: Wed, 15 Feb 2023 10:17:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9563a144accfeeb419abbe0f0bb78b5c2a957a08 commit 9563a144accfeeb419abbe0f0bb78b5c2a957a08 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;