]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement new SI prefixes in <ratio> for C++23 (P2734R0)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 23 Aug 2023 14:51:49 +0000 (15:51 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 24 Aug 2023 12:44:38 +0000 (13:44 +0100)
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.

libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/ratio
libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc

index b50050440d958c78ad9de5307e75bf2d72dd8c0c..80c13d4a447e0b9f7c3f4053fb10bdbf801aa022 100644 (file)
@@ -1582,6 +1582,14 @@ ftms = {
   };
 };
 
+ftms = {
+  name = ratio;
+  values = {
+    v = 202306;
+    cxxmin = 26;
+  };
+};
+
 ftms = {
   name = to_string;
   values = {
index 8b8c70a6e532becba164c9323e9d2da748931557..5bddb4b8adc614a136b880997f1e553ccc4a5a13 100644 (file)
 #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
index 1d285bf916f39738b936b9c5f6ef4b8b18d8ab24..c87f54fe1a2bb08ee0314b896c69464bb5f1ea33 100644 (file)
@@ -39,6 +39,9 @@
 #include <type_traits>
 #include <cstdint>             // intmax_t, uintmax_t
 
+#define __glibcxx_want_ratio
+#include <bits/version.h>
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -602,23 +605,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _R1, typename _R2>
     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
index 2e2a59c164cb66de068c4e14864223ae43faae05..62034e42a752bdfd7dbc1b87c4b071cb0fc1ac74 100644 (file)
@@ -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" }