libstdc++: Add assertions for preconditions in sampling distributions [PR 82584]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 8 Oct 2020 14:14:58 +0000 (15:14 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 8 Oct 2020 14:24:21 +0000 (15:24 +0100)
commitb2a96bf9dce41ee777b1669e4a8b4c6df3ff3613
tree1232ac1c462cbd462331ca81914b23cc948acbf7
parent5a448362da6133c3b16ffdb0c795b657af7fa5a4
libstdc++: Add assertions for preconditions in sampling distributions [PR 82584]

These three distributions all require 0 < S where S is the sum of the
weights. When the sum is zero there's an undefined FP division by zero.
Add assertions to help users diagnose the problem.

libstdc++-v3/ChangeLog:

PR libstdc++/82584
* include/bits/random.tcc
(discrete_distribution::param_type::_M_initialize)
(piecewise_constant_distribution::param_type::_M_initialize)
(piecewise_linear_distribution::param_type::_M_initialize):
Add assertions for positive sums..
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
line.
libstdc++-v3/include/bits/random.tcc
libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc