From: Jonathan Wakely Date: Wed, 7 Oct 2020 23:34:56 +0000 (+0100) Subject: libstdc++: Fix divide by zero in default template argument X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6ae17a3b6835b30102607d45ac89c7a668e2c8d4;p=gcc.git 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. --- 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 +}