From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 6FC673858C50; Mon, 18 Mar 2024 14:06:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FC673858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710770765; bh=HkXVeyQOAg5aB69NyDe/pdfD5WumGOdDVMmZJwShguI=; h=From:To:Subject:Date:From; b=iFpAirmTiirlw3IWqOIDGFLIOFpSSCRUA3R+YI4SZ23TyhKBo16UxNBNAS/FU/lK+ YxRSIam3m+gW4lXdKx2j8ef7Zlq9znC6Tqi1CbdhafejGOVrR6NEvVio/Q/W4RUWKw D3HVgLAPPUcows6sC1Gw3uamijnz1o4Voq5MFzmk= 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-10252] libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 6f5dcea85a31845ec6f4b6886734b0f02e013718 X-Git-Newrev: c285c1b9a940bde745f296e1bfc1a5cfddb63254 Message-Id: <20240318140605.6FC673858C50@sourceware.org> Date: Mon, 18 Mar 2024 14:06:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c285c1b9a940bde745f296e1bfc1a5cfddb63254 commit r12-10252-gc285c1b9a940bde745f296e1bfc1a5cfddb63254 Author: Jonathan Wakely Date: Thu Oct 26 16:51:30 2023 +0100 libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089] The incorrect errc constant here looks like a copy&paste error. libstdc++-v3/ChangeLog: PR libstdc++/112089 * include/std/shared_mutex (shared_lock::unlock): Change errc constant to operation_not_permitted. * testsuite/30_threads/shared_lock/locking/112089.cc: New test. (cherry picked from commit 0c305f3dec9a992dd775a3b9607b7b1e8c051859) Diff: --- libstdc++-v3/include/std/shared_mutex | 2 +- .../30_threads/shared_lock/locking/112089.cc | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex index 817a9587d87..0a61bedbe12 100644 --- a/libstdc++-v3/include/std/shared_mutex +++ b/libstdc++-v3/include/std/shared_mutex @@ -801,7 +801,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION unlock() { if (!_M_owns) - __throw_system_error(int(errc::resource_deadlock_would_occur)); + __throw_system_error(int(errc::operation_not_permitted)); _M_pm->unlock_shared(); _M_owns = false; } diff --git a/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc new file mode 100644 index 00000000000..432c17591a1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc @@ -0,0 +1,23 @@ +// { dg-do run { target c++14 } } +// { dg-require-gthreads "" } +// { dg-additional-options "-pthread" { target pthread } } + +#include +#include +#include + +// PR libstdc++/112089 shared_lock::unlock should throw operation_not_permitted + +int main() +{ + std::shared_lock l; + try + { + l.unlock(); + VERIFY( false ); + } + catch (const std::system_error& e) + { + VERIFY( e.code() == std::errc::operation_not_permitted ); + } +}