public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error
@ 2022-10-30 18:42 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
` (15 more replies)
0 siblings, 16 replies; 17+ messages in thread
From: littlefox+gcc-bugzilla@lf-net.org @ 2022-10-30 18:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Bug ID: 107466
Summary: [12 Regression] invalid -Wnarrowing error
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: littlefox+gcc-bugzilla@lf-net.org
Target Milestone: ---
Created attachment 53797
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53797&action=edit
Code triggering the error
Hi,
the attached code (and Godbolt[1]) fails in gcc 12+ with an -Wnarrowing error
in a stdlibc++ template instantiated with an uint16_t and apparently trying to
work with a 2^31:
/opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/random.tcc:545:9:
error: narrowing conversion of '2147483563' from 'unsigned int' to 'short
unsigned int' [-Wnarrowing]
545 | __lcg(__value == 0u ? default_seed : __value);
The code works fine in 11.3 and clang (14) and since it also works in clang
using libstdc++ 12.2, this error is probably in gcc itself and not in
libstdc++.
Tested this on my machine (debian testing), where it broke after a some system
updates where installed - including a gcc update. Then tested this in Godbolt
to check compiler versions and other configurations and asked in
libera.chat/#c++ for others to verify if my code makes sense - which it seems
to do.
Best, Mara
[1] Godbolt link: https://godbolt.org/z/sj18Mv5j9
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
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 ` pinskia at gcc dot gnu.org
2022-10-30 20:40 ` redi at gcc dot gnu.org
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30 18:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Shorter testcase (still includes):
#include <random>
void f() {
std::subtract_with_carry_engine<unsigned short, 12, 5, 12>();
}
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
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
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: redi at gcc dot gnu.org @ 2022-10-30 20:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think this is a compiler bug. Converting that value to uint16_t is
narrowing.
The problem is that the standard requires subtract_with_carry_engine<T> to use
linear_congruential_engine<T, 40014u, 0u, 2147483563u> where each of those
values is converted to T.
This appears to mean subtract_with_carry_engine cannot be used with uint16_t.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
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
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: littlefox+gcc-bugzilla@lf-net.org @ 2022-10-31 17:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #3 from Mara Sophie Grosch <littlefox+gcc-bugzilla@lf-net.org> ---
Standard explicitly allows using unsigned short though:
https://en.cppreference.com/w/cpp/numeric/random/subtract_with_carry_engine
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (2 preceding siblings ...)
2022-10-31 17:40 ` littlefox+gcc-bugzilla@lf-net.org
@ 2022-11-04 20:39 ` redi at gcc dot gnu.org
2022-11-05 10:26 ` rguenth at gcc dot gnu.org
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-04 20:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-11-04
Status|UNCONFIRMED |NEW
Component|c++ |libstdc++
Ever confirmed|0 |1
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's not the standard. That text comes from a general requirement in
[rand.req.gen] that applies to all engines and adaptors. The more specific
requirements for subtract_with_carry_engine say it uses a specialization of
linear_congruential_engine that is ill-formed. More specific requirements
overrule more general ones.
I've created a new LWG issue so this will get fixed in the standard. The best
suggestion so far is that it should use
linear_congruential_engine<uint_least32_t,...> instead of using its own
result_type.
Reassigning to component:libstdc++.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (3 preceding siblings ...)
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
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-05 10:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (4 preceding siblings ...)
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
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-25 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://cplusplus.github.io/LWG/issue3809
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12/13 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (5 preceding siblings ...)
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
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-28 15:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:a64775a0edd46980036b757041f0c065ed9f8d22
commit r13-4364-ga64775a0edd46980036b757041f0c065ed9f8d22
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Nov 28 09:44:52 2022 +0000
libstdc++: Make 16-bit std::subtract_with_carry_engine work [PR107466]
This implements the proposed resolution of LWG 3809, so that
std::subtract_with_carry_engine can be used with a 16-bit result_type.
Currently this produces a narrowing error when instantiating the
std::linear_congruential_engine to create the initial state. It also
truncates the default_seed constant when passing it as a result_type
argument.
Change the type of the constant to uint_least32_t and pass 0u when the
default_seed should be used.
libstdc++-v3/ChangeLog:
PR libstdc++/107466
* include/bits/random.h (subtract_with_carry_engine): Use 32-bit
type for default seed. Use 0u as default argument for
subtract_with_carry_engine(result_type) constructor and
seed(result_type) member function.
* include/bits/random.tcc (subtract_with_carry_engine): Use
32-bit type for default seed and engine used for initial state.
*
testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
New test.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (6 preceding siblings ...)
2022-11-28 15:19 ` cvs-commit at gcc dot gnu.org
@ 2023-04-27 11:42 ` rguenth at gcc dot gnu.org
2023-04-27 11:42 ` rguenth at gcc dot gnu.org
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-27 11:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (7 preceding siblings ...)
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
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-27 11:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (8 preceding siblings ...)
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
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-27 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:d8def0b55572fc5bc02a0fee6a98787cd50ee885
commit r12-9485-gd8def0b55572fc5bc02a0fee6a98787cd50ee885
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Nov 28 09:44:52 2022 +0000
libstdc++: Make 16-bit std::subtract_with_carry_engine work [PR107466]
This implements the proposed resolution of LWG 3809, so that
std::subtract_with_carry_engine can be used with a 16-bit result_type.
Currently this produces a narrowing error when instantiating the
std::linear_congruential_engine to create the initial state. It also
truncates the default_seed constant when passing it as a result_type
argument.
Change the type of the constant to uint_least32_t and pass 0u when the
default_seed should be used.
libstdc++-v3/ChangeLog:
PR libstdc++/107466
* include/bits/random.h (subtract_with_carry_engine): Use 32-bit
type for default seed. Use 0u as default argument for
subtract_with_carry_engine(result_type) constructor and
seed(result_type) member function.
* include/bits/random.tcc (subtract_with_carry_engine): Use
32-bit type for default seed and engine used for initial state.
*
testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
New test.
(cherry picked from commit a64775a0edd46980036b757041f0c065ed9f8d22)
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (9 preceding siblings ...)
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
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-27 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 12.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (10 preceding siblings ...)
2023-04-27 14:44 ` redi at gcc dot gnu.org
@ 2024-01-11 13:34 ` redi at gcc dot gnu.org
2024-01-13 0:14 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-11 13:34 UTC (permalink / raw)
To: gcc-bugs
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;
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (11 preceding siblings ...)
2024-01-11 13:34 ` redi at gcc dot gnu.org
@ 2024-01-13 0:14 ` cvs-commit at gcc dot gnu.org
2024-02-08 15:51 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-13 0:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:c224dec0e7c88e7a95633023018cdcb6ee87c65f
commit r14-7216-gc224dec0e7c88e7a95633023018cdcb6ee87c65f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jan 11 15:09:12 2024 +0000
libstdc++: Fix non-portable results from 64-bit
std::subtract_with_carry_engine [PR107466]
I implemented the resolution of LWG 3809 in r13-4364-ga64775a0edd469 but
it was recently noted in the MSVC STL github repo that the change causes
possible truncation for 64-bit seeds. Whether the truncation occurs (and
to what value) depends on the width of uint_least32_t which is not
portable, so the output of the PRNG for 64-bit seed values is no longer
the same as in C++20, and no longer portable across platforms.
That new issue was filed as LWG 4014. I proposed a new change which
reduces the seed by the LCG's modulus before the conversion to
uint_least32_t. This ensures that 64-bit seed values are consistently
reduced by the modulus before any truncation. This removes the
platform-dependent behaviour and restores the old behaviour for
std::subtract_with_carry_engine specializations using a 64-bit result
type (such as std::ranlux48_base).
libstdc++-v3/ChangeLog:
PR libstdc++/107466
* include/bits/random.tcc (subtract_with_carry_engine::seed):
Implement proposed resolution of LWG 4014.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
line number.
*
testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
Check for expected result of 64-bit engine with seed that
doesn't fit in 32-bits.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (12 preceding siblings ...)
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
15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-08 15:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:3bdd80d56aa07d5975f551e0026f3cf9411124bf
commit r13-8306-g3bdd80d56aa07d5975f551e0026f3cf9411124bf
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jan 11 15:09:12 2024 +0000
libstdc++: Fix non-portable results from 64-bit
std::subtract_with_carry_engine [PR107466]
I implemented the resolution of LWG 3809 in r13-4364-ga64775a0edd469 but
it was recently noted in the MSVC STL github repo that the change causes
possible truncation for 64-bit seeds. Whether the truncation occurs (and
to what value) depends on the width of uint_least32_t which is not
portable, so the output of the PRNG for 64-bit seed values is no longer
the same as in C++20, and no longer portable across platforms.
That new issue was filed as LWG 4014. I proposed a new change which
reduces the seed by the LCG's modulus before the conversion to
uint_least32_t. This ensures that 64-bit seed values are consistently
reduced by the modulus before any truncation. This removes the
platform-dependent behaviour and restores the old behaviour for
std::subtract_with_carry_engine specializations using a 64-bit result
type (such as std::ranlux48_base).
libstdc++-v3/ChangeLog:
PR libstdc++/107466
* include/bits/random.tcc (subtract_with_carry_engine::seed):
Implement proposed resolution of LWG 4014.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
line number.
*
testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
Check for expected result of 64-bit engine with seed that
doesn't fit in 32-bits.
(cherry picked from commit c224dec0e7c88e7a95633023018cdcb6ee87c65f)
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (13 preceding siblings ...)
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
15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-08 21:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:f2af87b9705d5a7e37b65bf342146ff25f025e49
commit r12-10143-gf2af87b9705d5a7e37b65bf342146ff25f025e49
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jan 11 15:09:12 2024 +0000
libstdc++: Fix non-portable results from 64-bit
std::subtract_with_carry_engine [PR107466]
I implemented the resolution of LWG 3809 in r13-4364-ga64775a0edd469 but
it was recently noted in the MSVC STL github repo that the change causes
possible truncation for 64-bit seeds. Whether the truncation occurs (and
to what value) depends on the width of uint_least32_t which is not
portable, so the output of the PRNG for 64-bit seed values is no longer
the same as in C++20, and no longer portable across platforms.
That new issue was filed as LWG 4014. I proposed a new change which
reduces the seed by the LCG's modulus before the conversion to
uint_least32_t. This ensures that 64-bit seed values are consistently
reduced by the modulus before any truncation. This removes the
platform-dependent behaviour and restores the old behaviour for
std::subtract_with_carry_engine specializations using a 64-bit result
type (such as std::ranlux48_base).
libstdc++-v3/ChangeLog:
PR libstdc++/107466
* include/bits/random.tcc (subtract_with_carry_engine::seed):
Implement proposed resolution of LWG 4014.
* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
line number.
*
testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
Check for expected result of 64-bit engine with seed that
doesn't fit in 32-bits.
(cherry picked from commit c224dec0e7c88e7a95633023018cdcb6ee87c65f)
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug libstdc++/107466] [12 Regression] invalid -Wnarrowing error with std::subtract_with_carry_engine
2022-10-30 18:42 [Bug c++/107466] New: [12 Regression] invalid -Wnarrowing error littlefox+gcc-bugzilla@lf-net.org
` (14 preceding siblings ...)
2024-02-08 21:28 ` cvs-commit at gcc dot gnu.org
@ 2024-02-08 21:42 ` redi at gcc dot gnu.org
15 siblings, 0 replies; 17+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-08 21:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution|--- |FIXED
--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And fixed for real now, for 12.4, 13.3 and trunk.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2024-02-08 21:42 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
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).