]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Reduce header dependencies for C++20 (PR 92546)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 17 Feb 2020 15:25:33 +0000 (15:25 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 17 Feb 2020 15:43:43 +0000 (15:43 +0000)
In C++20 <memory> depends on <bits/ranges_unitialized.h> which
depends on <bits/random.h> just for a single concept. Including
<bits/random.h> also requires including <cmath>, which is huge due to
the C++17 special functions.

This change moves the concept to the <bits/uniform_int_dist.h> internal
header that exists so that <bits/stl_algobase.h> doesn't need to include
<bits/random.h>.

PR libstdc++/92546 (partial)
* include/bits/random.h (uniform_random_bit_generator): Move definition
to <bits/uniform_int_dist.h>.
* include/bits/ranges_algo.h: Include <bits/uniform_int_dist.h> instead
of <bits/random.h>.
* include/bits/ranges_algobase.h: Do not include <cmath>.
* include/bits/uniform_int_dist.h (uniform_random_bit_generator):
Move here.
* include/std/ranges: Do not include <limits>.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/random.h
libstdc++-v3/include/bits/ranges_algo.h
libstdc++-v3/include/bits/ranges_algobase.h
libstdc++-v3/include/bits/uniform_int_dist.h
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc

index 954eb673184e3d89beb176d6fd3d72bf9347e07a..f4477aaa6f2d5478ab417a79644bf4b7dec10362 100644 (file)
@@ -1,5 +1,16 @@
 2020-02-17  Jonathan Wakely  <jwakely@redhat.com>
 
+       PR libstdc++/92546 (partial)
+       * include/bits/random.h (uniform_random_bit_generator): Move definition
+       to <bits/uniform_int_dist.h>.
+       * include/bits/ranges_algo.h: Include <bits/uniform_int_dist.h> instead
+       of <bits/random.h>.
+       * include/bits/ranges_algobase.h: Do not include <cmath>.
+       * include/bits/uniform_int_dist.h (uniform_random_bit_generator):
+       Move here.
+       * include/std/ranges: Do not include <limits>.
+       * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.
+
        PR libstdc++/92546 (partial)
        * include/Makefile.am: Add new header.
        * include/Makefile.in: Regenerate.
index d4aebf45af00ed6b624ff367a94945f7a52f5fcc..19307fbc3ca401976ef6823e8fda893e4a263751 100644 (file)
@@ -33,9 +33,6 @@
 
 #include <vector>
 #include <bits/uniform_int_dist.h>
-#if __cplusplus > 201703L
-# include <concepts>
-#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -51,18 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * @{
    */
 
-#ifdef __cpp_lib_concepts
-  /// Requirements for a uniform random bit generator.
-  template<typename _Gen>
-    concept uniform_random_bit_generator
-      = invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>>
-      && requires
-      {
-       { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
-       { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
-       requires bool_constant<(_Gen::min() < _Gen::max())>::value;
-      };
-#endif
+  // std::uniform_random_bit_generator is defined in <bits/uniform_int_dist.h>
 
   /**
    * @brief A function template for converting the output of a (integral)
index ff1b40f6ace1c5d5547a31ea1bb4c2fa38cbeecb..f3a349ef8393b3154baa81377faac1300aefb7a9 100644 (file)
@@ -33,7 +33,7 @@
 #if __cplusplus > 201703L
 
 #include <bits/ranges_algobase.h>
-#include <bits/random.h> // concept uniform_random_bit_generator
+#include <bits/uniform_int_dist.h> // concept uniform_random_bit_generator
 
 #if __cpp_lib_concepts
 namespace std _GLIBCXX_VISIBILITY(default)
index cc24483b2d3ff7b173001b29d91ea4448cbee3b2..eedd29f570a6c6ce94f8ae03e29f835b0dde250e 100644 (file)
@@ -32,7 +32,6 @@
 
 #if __cplusplus > 201703L
 
-#include <cmath>
 #include <compare>
 #include <iterator>
 // #include <bits/range_concepts.h>
index d2a015706352f1b0227b252c0e3dbdbe3caa244e..e3d7934e9977c632de63bd9821f0bda921c2cd8c 100644 (file)
 
 #include <type_traits>
 #include <limits>
+#if __cplusplus > 201703L
+# include <concepts>
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#ifdef __cpp_lib_concepts
+  /// Requirements for a uniform random bit generator.
+  template<typename _Gen>
+    concept uniform_random_bit_generator
+      = invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>>
+      && requires
+      {
+       { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>;
+       { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>;
+       requires bool_constant<(_Gen::min() < _Gen::max())>::value;
+      };
+#endif
+
   namespace __detail
   {
     /* Determine whether number is a power of 2.  */
index 970e904bdddb4264a74aff32d26fa3ad561b04c0..b9ac528fdff5121a3469673b03a4fa47b160bb6a 100644 (file)
@@ -42,7 +42,6 @@
 #include <compare>
 #include <initializer_list>
 #include <iterator>
-#include <limits>
 #include <optional>
 #include <tuple>
 
index 91e5566c54ae3176d8d17ce11b409c0246a4dc18..f808132e9ea47a9276ee7950e19c6414c48c9de1 100644 (file)
@@ -10,6 +10,6 @@ std::__detail::_Adaptor<std::mt19937, unsigned long> aurng(urng);
 auto x = std::generate_canonical<std::size_t,
                        std::numeric_limits<std::size_t>::digits>(urng);
 
-// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 172 }
+// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 158 }
 
 // { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3281 }