https://gcc.gnu.org/g:bdd2753f5f021a15a6c4ef02565356985fea1300

commit r16-556-gbdd2753f5f021a15a6c4ef02565356985fea1300
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Fri May 9 17:50:52 2025 +0100

    libstdc++: Restore std::scoped_lock for non-gthreads targets [PR120198]
    
    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 <tkami...@redhat.com>

Diff:
---
 libstdc++-v3/include/bits/version.def              |  2 --
 libstdc++-v3/include/bits/version.h                |  2 +-
 libstdc++-v3/include/std/mutex                     |  2 +-
 .../scoped_lock/requirements/typedefs.cc           | 28 ++++++++++++++++++----
 4 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index f4d3de88bb2b..2d34a8dff7fc 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -679,8 +679,6 @@ ftms = {
   values = {
     v = 201703;
     cxxmin = 17;
-    hosted = yes;
-    gthread = yes;
   };
 };
 
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index d5d75cef2de1..24831f70b417 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -751,7 +751,7 @@
 #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
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index b3f89c0b9435..e575a81c138e 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -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
diff --git 
a/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc 
b/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc
index 4cd07da44657..ba52b36a3111 100644
--- a/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc
@@ -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.
@@ -29,9 +28,30 @@
 # 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>);
 }

Reply via email to