]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Restore std::scoped_lock for non-gthreads targets [PR120198]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 9 May 2025 16:50:52 +0000 (17:50 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 12 May 2025 11:26:53 +0000 (12:26 +0100)
This was a regression introduced with using version.def to define
feature test macros (r14-3248-g083b7f2833d71d). std::scoped_lock doesn't
need to depend on gthreads and so can be defined unconditionally, even
for freestanding.

libstdc++-v3/ChangeLog:

PR libstdc++/120198
* include/bits/version.def (scoped_lock): Do not depend on
gthreads or hosted.
* include/bits/version.h: Regenerate.
* include/std/mutex (scoped_lock): Update comment.
* testsuite/30_threads/scoped_lock/requirements/typedefs.cc:
Remove dg-require-gthreads and use custom lockable type instead
of std::mutex. Check that typedef is only present for a single
template argument.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/mutex
libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc

index f4d3de88bb2ba48e829920edb467704279195560..2d34a8dff7fc81d82d63e3b9334be9e6e6e05e04 100644 (file)
@@ -679,8 +679,6 @@ ftms = {
   values = {
     v = 201703;
     cxxmin = 17;
-    hosted = yes;
-    gthread = yes;
   };
 };
 
index d5d75cef2de14b5a58f5d844f62d9b21833816dc..24831f70b417ec107e25a3cf4ffc243fe629bc9e 100644 (file)
 #undef __glibcxx_want_parallel_algorithm
 
 #if !defined(__cpp_lib_scoped_lock)
-# if (__cplusplus >= 201703L) && defined(_GLIBCXX_HAS_GTHREADS) && _GLIBCXX_HOSTED
+# if (__cplusplus >= 201703L)
 #  define __glibcxx_scoped_lock 201703L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_scoped_lock)
 #   define __cpp_lib_scoped_lock 201703L
index b3f89c0b9435c09a396e546491faaccb88bdfadc..e575a81c138e674514a75f02be3b4629466247d0 100644 (file)
@@ -733,7 +733,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     }
 
-#ifdef __cpp_lib_scoped_lock // C++ >= 17 && hosted && gthread
+#ifdef __cpp_lib_scoped_lock // C++ >= 17
   /** @brief A scoped lock type for multiple lockable objects.
    *
    * A scoped_lock controls mutex ownership within a scope, releasing
index 4cd07da44657780e6d3b369f31776e10e9fceb13..ba52b36a311199f9312e7c5b47cf9193c710c92e 100644 (file)
@@ -1,5 +1,4 @@
 // { dg-do compile { target c++17 } }
-// { dg-require-gthreads "" }
 // { dg-add-options no_pch }
 
 // Copyright (C) 2017-2025 Free Software Foundation, Inc.
 # error "Feature-test macro for scoped_lock has wrong value"
 #endif
 
+struct BasicLockable
+{
+  BasicLockable() = default;
+  ~BasicLockable() = default;
+  void lock() { }
+  void unlock() { }
+};
+
 void test01()
 {
-  // Check for required typedefs
-  typedef std::scoped_lock<std::mutex> test_type;
-  typedef test_type::mutex_type mutex_type;
+  // Check for required typedef.
+  using test_type = std::scoped_lock<BasicLockable>;
+  static_assert(std::is_same_v<test_type::mutex_type, BasicLockable>);
+}
+
+template<typename T, typename = void>
+constexpr bool has_mutex_type = false;
+
+template<typename T>
+constexpr bool has_mutex_type<T, std::void_t<typename T::mutex_type>> = true;
+
+void test02()
+{
+  // Check that typedef is absent as required.
+  using test_type = std::scoped_lock<BasicLockable, BasicLockable>;
+  static_assert(!has_mutex_type<test_type>);
 }