From: Jonathan Wakely Date: Sat, 15 Feb 2020 08:58:43 +0000 (+0000) Subject: libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5b1d588509551291f4028497858ee9e04ce0bdee;p=gcc.git 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 --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d1e5aad1b68..8e248703430 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2020-02-15 Jonathan Wakely + + * 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 * include/Makefile.am: Add . 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>; { _Gen::max() } -> same_as>; + 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 ); + +struct N12 +{ + unsigned operator()(); + static unsigned min() { return 0; } // not constexpr + static constexpr unsigned max() { return 1; } +}; + +static_assert( ! std::uniform_random_bit_generator ); // 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 ); // 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 ); // 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 aurng(urng); auto x = std::generate_canonical::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 }