From 6ae17a3b6835b30102607d45ac89c7a668e2c8d4 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 8 Oct 2020 00:34:56 +0100 Subject: [PATCH] libstdc++: Fix divide by zero in default template argument libstdc++-v3/ChangeLog: * include/bits/random.h (__detail::_Mod): Avoid divide by zero. * testsuite/26_numerics/random/linear_congruential_engine/operators/call.cc: New test. --- libstdc++-v3/include/bits/random.h | 2 +- .../operators/call.cc | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/call.cc diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 4a6558c966a..920f3d91513 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -109,7 +109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template= __m - 1), - bool __schrage_ok = __m % __a < __m / __a> + bool __schrage_ok = __a != 0 && __m % __a < __m / __a> struct _Mod { typedef typename _Select_uint_least_t. + +// { dg-do compile { target c++11 } } + +#include + +unsigned +test01() +{ + std::linear_congruential_engine l; + return l(); // this used to result in divide by zero +} -- 2.30.2