From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5AE9F3858024; Thu, 11 Jan 2024 13:34:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AE9F3858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704980100; bh=Q6sQ2F0d4SkZsqJIM7hnTN/kyR1b+KPh6xFsslEG2UY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PbHsiNJkuZfjmViCzOXzT3V7V2MFz2KAc9CPZBmHclaFjukOB3ooEadItenlkfSri MaLC5t74tFiKOqEhBNBiRJy2WRh+0qIZAQLrO3w6F0eHfJQGkYjvwOLzg9v7nAETUG 5eHDtUHl6qtdnSKkoqFgj8f5H+DCnmd0INQVq/Bo= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine Date: Thu, 11 Jan 2024 13:34:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: diagnostic, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status resolution Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107466 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED |--- --- Comment #9 from Jonathan Wakely --- 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 supposed to wo= rk? + // 4014. LWG 3809 changes behavior of some existing code + if (__value =3D=3D 0u) + __value =3D default_seed; + else + __value %=3D 2147483563u; + std::linear_congruential_engine - __lcg(__value =3D=3D 0u ? default_seed : __value); + __lcg(__value); const size_t __n =3D (__w + 31) / 32;=