From: Jonathan Wakely Date: Fri, 9 May 2025 16:50:52 +0000 (+0100) Subject: libstdc++: Restore std::scoped_lock for non-gthreads targets [PR120198] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bdd2753f5f021a15a6c4ef02565356985fea1300;p=thirdparty%2Fgcc.git 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 --- 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 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); }