]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 26 Oct 2023 15:51:30 +0000 (16:51 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 18 Mar 2024 13:50:53 +0000 (13:50 +0000)
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)

libstdc++-v3/include/std/shared_mutex
libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc [new file with mode: 0644]

index 817a9587d87790aeca380a8961fb49d276948454..0a61bedbe12fb5470a43122a151742a264d4ac46 100644 (file)
@@ -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 (file)
index 0000000..432c175
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-do run { target c++14 } }
+// { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+
+#include <shared_mutex>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+// PR libstdc++/112089 shared_lock::unlock should throw operation_not_permitted
+
+int main()
+{
+  std::shared_lock<std::shared_timed_mutex> l;
+  try
+  {
+    l.unlock();
+    VERIFY( false );
+  }
+  catch (const std::system_error& e)
+  {
+    VERIFY( e.code() == std::errc::operation_not_permitted );
+  }
+}