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.
This commit is contained in:
Jonathan Wakely 2020-02-15 08:58:43 +00:00
parent 458c8d6459
commit 5b1d588509
4 changed files with 36 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2020-02-15 Jonathan Wakely <jwakely@redhat.com>
* 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.
2020-02-13 Patrick Palka <ppalka@redhat.com>
* include/Makefile.am: Add <bits/ranges_uninitialized.h>.

View File

@ -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

View File

@ -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

View 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 *-*-* } 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 }