From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 97FE23858C2B; Thu, 24 Aug 2023 12:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97FE23858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692881096; bh=sCTavWSfzt+KnEHR3B3IvU7HpqiSy0OscBdYOKFdG9E=; h=From:To:Subject:Date:From; b=UbusZ6jzjv8EMKCnbikgReTi7Q37s7fqXGQBGWP6mOO3KeaDn4oqkzwa3Z/dGl8/8 mq9NTCx9XYBn0M1tFbMO8qdWcHAhC04WMuihuqofyQUxTANg8nJ9a6g6mg0OCjfleM oJZ503M2jyukl4zsPET5srm1zJgudIuogZg/iAKY= 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 r14-3454] libstdc++: Implement new SI prefixes in for C++23 (P2734R0) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: d96659e34cdcf43640541e1b7401ac546e0d1bf5 X-Git-Newrev: c47430bba62a49a2ca10c99380ce87ceafca8e68 Message-Id: <20230824124456.97FE23858C2B@sourceware.org> Date: Thu, 24 Aug 2023 12:44:56 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c47430bba62a49a2ca10c99380ce87ceafca8e68 commit r14-3454-gc47430bba62a49a2ca10c99380ce87ceafca8e68 Author: Jonathan Wakely Date: Wed Aug 23 15:51:49 2023 +0100 libstdc++: Implement new SI prefixes in for C++23 (P2734R0) This is a no-op for libstdc++, because our intmax_t is a 64-bit type and so is incapable of representing the largest and smallest ratios from C++11, let alone the new ones. I've added them to the file anyway (and defined the feature test macro) so that if somebody ports libstdc++ to a target with 128-bit intmax_t then they'll be present. libstdc++-v3/ChangeLog: * include/bits/version.def (__cpp_lib_ratio): Define. * include/bits/version.h: Regenerate. * include/std/ratio (quecto, ronto, yocto, zepto) (zetta, yotta, ronna, quetta): Define. * testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Adjust dg-error line numbers. Diff: --- libstdc++-v3/include/bits/version.def | 8 ++++ libstdc++-v3/include/bits/version.h | 11 +++++ libstdc++-v3/include/std/ratio | 56 +++++++++++++++------- .../20_util/ratio/operations/ops_overflow_neg.cc | 6 +-- 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index b50050440d95..80c13d4a447e 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -1582,6 +1582,14 @@ ftms = { }; }; +ftms = { + name = ratio; + values = { + v = 202306; + cxxmin = 26; + }; +}; + ftms = { name = to_string; values = { diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 8b8c70a6e532..5bddb4b8adc6 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -1940,6 +1940,17 @@ #undef __glibcxx_want_string_resize_and_overwrite // from version.def line 1586 +#if !defined(__cpp_lib_ratio) +# if (__cplusplus > 202302L) +# define __glibcxx_ratio 202306L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_ratio) +# define __cpp_lib_ratio 202306L +# endif +# endif +#endif /* !defined(__cpp_lib_ratio) && defined(__glibcxx_want_ratio) */ +#undef __glibcxx_want_ratio + +// from version.def line 1594 #if !defined(__cpp_lib_to_string) # if (__cplusplus > 202302L) && _GLIBCXX_HOSTED && (__glibcxx_to_chars) # define __glibcxx_to_string 202306L diff --git a/libstdc++-v3/include/std/ratio b/libstdc++-v3/include/std/ratio index 1d285bf916f3..c87f54fe1a2b 100644 --- a/libstdc++-v3/include/std/ratio +++ b/libstdc++-v3/include/std/ratio @@ -39,6 +39,9 @@ #include #include // intmax_t, uintmax_t +#define __glibcxx_want_ratio +#include + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -602,23 +605,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type; - - typedef ratio<1, 1000000000000000000> atto; - typedef ratio<1, 1000000000000000> femto; - typedef ratio<1, 1000000000000> pico; - typedef ratio<1, 1000000000> nano; - typedef ratio<1, 1000000> micro; - typedef ratio<1, 1000> milli; - typedef ratio<1, 100> centi; - typedef ratio<1, 10> deci; - typedef ratio< 10, 1> deca; - typedef ratio< 100, 1> hecto; - typedef ratio< 1000, 1> kilo; - typedef ratio< 1000000, 1> mega; - typedef ratio< 1000000000, 1> giga; - typedef ratio< 1000000000000, 1> tera; - typedef ratio< 1000000000000000, 1> peta; - typedef ratio< 1000000000000000000, 1> exa; +#if __INTMAX_WIDTH__ >= 96 +# if __cpp_lib_ratio >= 202306L +# if __INTMAX_WIDTH__ >= 128 + using quecto = ratio< 1, 1000000000000000000000000000000>; +# endif + using ronto = ratio< 1, 1000000000000000000000000000>; +# endif + using yocto = ratio< 1, 1000000000000000000000000>; + using zepto = ratio< 1, 1000000000000000000000>; +#endif + using atto = ratio< 1, 1000000000000000000>; + using femto = ratio< 1, 1000000000000000>; + using pico = ratio< 1, 1000000000000>; + using nano = ratio< 1, 1000000000>; + using micro = ratio< 1, 1000000>; + using milli = ratio< 1, 1000>; + using centi = ratio< 1, 100>; + using deci = ratio< 1, 10>; + using deca = ratio< 10, 1>; + using hecto = ratio< 100, 1>; + using kilo = ratio< 1000, 1>; + using mega = ratio< 1000000, 1>; + using giga = ratio< 1000000000, 1>; + using tera = ratio< 1000000000000, 1>; + using peta = ratio< 1000000000000000, 1>; + using exa = ratio< 1000000000000000000, 1>; +#if __INTMAX_WIDTH__ >= 96 + using zetta = ratio< 1000000000000000000000, 1>; + using yotta = ratio<1000000000000000000000000, 1>; +# if __cpp_lib_ratio >= 202306L + using ronna = ratio<1000000000000000000000000000, 1>; +# if __INTMAX_WIDTH__ >= 128 + using quetta = ratio<1000000000000000000000000000000, 1>; +# endif +# endif +#endif /// @} group ratio _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc index 2e2a59c164cb..62034e42a752 100644 --- a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc +++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc @@ -43,9 +43,9 @@ test02() // { dg-error "expected initializer" "" { target *-*-* } 35 } // { dg-error "expected initializer" "" { target *-*-* } 37 } // { dg-error "overflow in addition" "" { target *-*-* } 0 } -// { dg-error "overflow in multiplication" "" { target *-*-* } 98 } -// { dg-error "overflow in multiplication" "" { target *-*-* } 100 } -// { dg-error "overflow in multiplication" "" { target *-*-* } 102 } +// { dg-error "overflow in multiplication" "" { target *-*-* } 101 } +// { dg-error "overflow in multiplication" "" { target *-*-* } 103 } +// { dg-error "overflow in multiplication" "" { target *-*-* } 105 } // { dg-error "overflow in constant expression" "" { target *-*-* } 0 } // { dg-error "narrowing conversion" "" { target *-*-* } 0 } // { dg-prune-output "out of range" }