public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-107466-4-96r30TKyUM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107466-4@http.gcc.gnu.org/bugzilla/>

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;

  parent reply	other threads:[~2024-01-11 13:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
2022-10-30 18:50 ` [Bug c++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine pinskia at gcc dot gnu.org
2022-10-30 20:40 ` redi at gcc dot gnu.org
2022-10-31 17:40 ` littlefox+gcc-bugzilla@lf-net.org
2022-11-04 20:39 ` [Bug libstdc++/107466] " redi at gcc dot gnu.org
2022-11-05 10:26 ` rguenth at gcc dot gnu.org
2022-11-25  9:38 ` redi at gcc dot gnu.org
2022-11-28 15:19 ` cvs-commit at gcc dot gnu.org
2023-04-27 11:42 ` [Bug libstdc++/107466] [12 " rguenth at gcc dot gnu.org
2023-04-27 11:42 ` rguenth at gcc dot gnu.org
2023-04-27 14:43 ` cvs-commit at gcc dot gnu.org
2023-04-27 14:44 ` redi at gcc dot gnu.org
2024-01-11 13:34 ` redi at gcc dot gnu.org [this message]
2024-01-13  0:14 ` cvs-commit at gcc dot gnu.org
2024-02-08 15:51 ` cvs-commit at gcc dot gnu.org
2024-02-08 21:28 ` cvs-commit at gcc dot gnu.org
2024-02-08 21:42 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107466-4-96r30TKyUM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).