diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-05-09 17:50:52 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-05-12 12:26:53 +0100 |
commit | bdd2753f5f021a15a6c4ef02565356985fea1300 (patch) | |
tree | 907e63cbb014d28ae4f3281346ee50094cfb2d99 | |
parent | 67c8e777d466d3bed9830bf01841c96b6881b58d (diff) | |
download | gcc-bdd2753f5f021a15a6c4ef02565356985fea1300.zip gcc-bdd2753f5f021a15a6c4ef02565356985fea1300.tar.gz gcc-bdd2753f5f021a15a6c4ef02565356985fea1300.tar.bz2 |
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 <tkaminsk@redhat.com>
-rw-r--r-- | libstdc++-v3/include/bits/version.def | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/version.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/std/mutex | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/30_threads/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 f4d3de8..2d34a8d 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 d5d75ce..24831f7 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 b3f89c0..e575a81 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 4cd07da..ba52b36 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>); } |