https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED |--- --- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> --- I'm reopening this because the fix changes the behaviour of some code: https://cplusplus.github.io/LWG/issue4014 As noted there, std::ranlux48_base(UINT_MAX+1LL)() changed behaviour. Originally that yielded 22575453646312 but after the commits above it yields 23223501020940 This is what I proposed for 4014 and restores the original behaviour: --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -541,8 +541,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION subtract_with_carry_engine<_UIntType, __w, __s, __r>:: seed(result_type __value) { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3809. Is std::subtract_with_carry_engine<uint16_t> supposed to work? + // 4014. LWG 3809 changes behavior of some existing code + if (__value == 0u) + __value = default_seed; + else + __value %= 2147483563u; + std::linear_congruential_engine<uint_least32_t, 40014u, 0u, 2147483563u> - __lcg(__value == 0u ? default_seed : __value); + __lcg(__value); const size_t __n = (__w + 31) / 32;