#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
}
}
-#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
// { 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>);
}