From c50b8d550d20e42e88b70f0a6e0f6798e30ddcb2 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 9 May 2025 17:50:52 +0100 Subject: [PATCH] libstdc++: Restore std::scoped_lock for non-gthreads targets [PR120198] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit bdd2753f5f021a15a6c4ef02565356985fea1300) --- 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 91c144cc4f0a..49c0a0a9fc06 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -668,8 +668,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 82901af2ad62..5c6d8a9f8afc 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -739,7 +739,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 8dd9b23191fd..e4b14c017201 100644 --- a/libstdc++-v3/include/std/mutex +++ b/libstdc++-v3/include/std/mutex @@ -731,7 +731,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 5ee9104b17d4..335b8e791471 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-2024 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 test_type; - typedef test_type::mutex_type mutex_type; + // Check for required typedef. + using test_type = std::scoped_lock; + static_assert(std::is_same_v); +} + +template +constexpr bool has_mutex_type = false; + +template +constexpr bool has_mutex_type> = true; + +void test02() +{ + // Check that typedef is absent as required. + using test_type = std::scoped_lock; + static_assert(!has_mutex_type); } -- 2.47.2