From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 2B8D53851C2A; Wed, 7 Oct 2020 23:45:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B8D53851C2A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-3711] libstdc++: Fix divide by zero in default template argument X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 23f75da95f5e8e09e9fcbd5b0d2885e6c44739aa X-Git-Newrev: 6ae17a3b6835b30102607d45ac89c7a668e2c8d4 Message-Id: <20201007234545.2B8D53851C2A@sourceware.org> Date: Wed, 7 Oct 2020 23:45:45 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Oct 2020 23:45:45 -0000 https://gcc.gnu.org/g:6ae17a3b6835b30102607d45ac89c7a668e2c8d4 commit r11-3711-g6ae17a3b6835b30102607d45ac89c7a668e2c8d4 Author: Jonathan Wakely Date: Thu Oct 8 00:34:56 2020 +0100 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: --- libstdc++-v3/include/bits/random.h | 2 +- .../linear_congruential_engine/operators/call.cc | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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 +}