]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Make std::random_device throw std::system_error [PR105081]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Apr 2023 14:23:57 +0000 (15:23 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Apr 2023 10:28:39 +0000 (11:28 +0100)
commitf9412cedd6c0e7417b30d9a80d3f45c8746223b4
tree07675ffc3873c74bc79453927dd0f224829c7493
parentd8842271ebf9a81128df9ae80e1d3b688749eac8
libstdc++: Make std::random_device throw std::system_error [PR105081]

This changes std::random_device constructors to throw std::system_error
(with EINVAL as the error code) when the constructor argument is
invalid. We can also throw std::system_error when read(2) fails so that
the exception includes the additional information provided by errno.

As noted in the PR, this is consistent with libc++, and doesn't break
any existing code which catches std::runtime_error, because those
handlers will still catch std::system_error.

libstdc++-v3/ChangeLog:

PR libstdc++/105081
* src/c++11/random.cc (__throw_syserr): New function.
(random_device::_M_init, random_device::_M_init_pretr1): Use new
function for bad tokens.
(random_device::_M_getval): Use new function for read errors.
* testsuite/util/testsuite_random.h (random_device_available):
Change catch handler to use std::system_error.
libstdc++-v3/src/c++11/random.cc
libstdc++-v3/testsuite/util/testsuite_random.h