https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118665
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |10.5.0
Summary|std::uniform_int_distributi |[13/14/15/16 Regression]
|on infinite loop with |std::uniform_int_distributi
|generator returning 0 |on infinite loop with
| |generator returning 0
Known to fail| |11.1.0, 16.0
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This started with r11-3757-g98c37d3bacbb2f i.e.
"libstdc++: Optimize uniform_int_distribution using Lemire's algorithm"
This loops never terminates if the URBG always returns 0:
// reference: Fast Random Integer Generation in an Interval
// ACM Transactions on Modeling and Computer Simulation 29 (1), 2019
// https://arxiv.org/abs/1805.10941
_Wp __product = _Wp(__g()) * _Wp(__range);
_Up __low = _Up(__product);
if (__low < __range)
{
_Up __threshold = -__range % __range;
while (__low < __threshold)
{
__product = _Wp(__g()) * _Wp(__range);
__low = _Up(__product);
}
}
__range is the size of the uniform_int_distribution's output range, which is 43
here. The threshold is 16, and __low is always zero, and so always below the
threshold.