From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 1031C3858431; Thu, 2 Feb 2023 09:34:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1031C3858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675330492; bh=D8CksKa2Xm0bl+uT6JqmkbxcJbjyg70UHrvBZg6rG24=; h=From:To:Subject:Date:From; b=pN9NSzXPPVeo75XdfEdyTZ+yiQD8mBlxBN0ZNUQNoZfa0tBA4NBsdUIFdn84fkkrv BRkyEqBlo1cCO7nVsWQn20aZo3CJzCBz+4HEQrYbBMWxGGiOtbd/gSCNexKCqNetKR OCSj75rLb63pWYSxuJce+gpiTeRvStOTP3PAYPsY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-9100] libstdc++: Fix std::random_device for avr X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: aa18735f7aa99b40c56b3e3aacb1b28cb805bb90 X-Git-Newrev: cc0394346ac49659d446b2ef35c40ba1ef3cd117 Message-Id: <20230202093452.1031C3858431@sourceware.org> Date: Thu, 2 Feb 2023 09:34:52 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cc0394346ac49659d446b2ef35c40ba1ef3cd117 commit r12-9100-gcc0394346ac49659d446b2ef35c40ba1ef3cd117 Author: Jonathan Wakely Date: Tue Jan 31 22:28:16 2023 +0000 libstdc++: Fix std::random_device for avr This fixes a build failure that affects avr, but could affect other targets in theory. The _M_fini function should not try to use ::open or ::fopen if _GLIBCXX_USE_DEV_RANDOM is not defined, because no file can ever have been opened. libstdc++-v3/ChangeLog: * src/c++11/random.cc (random_device::_M_fini): Do not try to close the file handle if the target doesn't support the /dev/random and /dev/urandom files. (cherry picked from commit 277dd6ea416718ba5493023b5a4660ecdbaf936c) Diff: --- libstdc++-v3/src/c++11/random.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index 8b5175a4ebf..38e2153ec17 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -548,6 +548,7 @@ namespace std _GLIBCXX_VISIBILITY(default) } #endif +#ifdef _GLIBCXX_USE_DEV_RANDOM #ifdef USE_POSIX_FILE_IO ::close(_M_fd); _M_fd = -1; @@ -555,6 +556,7 @@ namespace std _GLIBCXX_VISIBILITY(default) std::fclose(static_cast(_M_file)); #endif _M_file = nullptr; +#endif } random_device::result_type