diff mbox series

libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator

Message ID 20200215103822.GA1464289@redhat.com
State New
Headers show
Series libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator | expand

Commit Message

Jonathan Wakely Feb. 15, 2020, 10:38 a.m. UTC
* include/bits/random.h (uniform_random_bit_generator): Require min()
	and max() to be constant expressions and min() to be less than max().
	* testsuite/26_numerics/random/concept.cc: Check additional cases.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.

Tested powerpc64le-linux, committed to master.
commit 5b1d588509551291f4028497858ee9e04ce0bdee
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Feb 15 08:58:43 2020 +0000

    libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator
    
            * include/bits/random.h (uniform_random_bit_generator): Require min()
            and max() to be constant expressions and min() to be less than max().
            * testsuite/26_numerics/random/concept.cc: Check additional cases.
            * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 3eefdefc96f..d4aebf45af0 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -60,6 +60,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	{ _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
 
diff --git a/libstdc++-v3/testsuite/26_numerics/random/concept.cc b/libstdc++-v3/testsuite/26_numerics/random/concept.cc
index 69a7fc1e674..cb1ea882e16 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/concept.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/concept.cc
@@ -219,3 +219,30 @@  struct N11
 };
 
 static_assert( ! std::uniform_random_bit_generator<N11> );
+
+struct N12
+{
+  unsigned operator()();
+  static unsigned min() { return 0; } // not constexpr
+  static constexpr unsigned max() { return 1; }
+};
+
+static_assert( ! std::uniform_random_bit_generator<N12> ); // LWG 3150
+
+struct N13
+{
+  unsigned operator()();
+  static constexpr unsigned min() { return 0; }
+  static unsigned max() { return 1; } // not constexpr
+};
+
+static_assert( ! std::uniform_random_bit_generator<N13> ); // LWG 3150
+
+struct N14
+{
+  unsigned operator()();
+  static constexpr unsigned min() { return 1; }
+  static constexpr unsigned max() { return 0; } // max not greater than min
+};
+
+static_assert( ! std::uniform_random_bit_generator<N14> ); // LWG 3150
diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
index 201b87e9c52..91e5566c54a 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
@@ -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 *-*-* } 171 }
+// { 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 *-*-* } 3281 }