| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
// Bug 114359 - std::binomial_distribution hangs in infinite loop |
| 4 |
|
| 5 |
// { dg-require-cmath "" } |
| 6 |
|
| 7 |
// The requirement above is not strictly true. The test should work |
| 8 |
// without cmath, and it probably does, but without cmath, |
| 9 |
// binomial_distribution::operator() skips the optimized algorithm and |
| 10 |
// calls _M_waiting to loop a gazillion times. On aarch64-rtems6 |
| 11 |
// qemu, that loop takes over 5 minutes to go through a small fraction |
| 12 |
// of the iteration space (__x at 22k, limited at 1G; __sum at 2e-5, |
| 13 |
// limited at 0.69). The bug we're regression-testing here was in the |
| 14 |
// cmath-requiring bit, so even if this could conceivably not time out |
| 15 |
// on a really fast machine, there's hardly any reason to exercise |
| 16 |
// this extreme case. |
| 17 |
|
| 18 |
#include <random> |
| 19 |
|
| 20 |
int main() |
| 21 |
{ |
| 22 |
std::default_random_engine g{}; |
| 23 |
std::binomial_distribution<std::uint32_t> b(1U << 30); |
| 24 |
b(g); // hangs forever |
| 25 |
} |