]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Make 16-bit std::subtract_with_carry_engine work [PR107466]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 28 Nov 2022 09:44:52 +0000 (09:44 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 28 Nov 2022 15:02:04 +0000 (15:02 +0000)
commita64775a0edd46980036b757041f0c065ed9f8d22
tree8756b771d7dfd1eb705dd87a1522a959cc0c772a
parentbe7ea145514eba69a3d53340da3f05f804e48833
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.
libstdc++-v3/include/bits/random.h
libstdc++-v3/include/bits/random.tcc
libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc [new file with mode: 0644]