]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Use std::conditional_t instead of lambda to select semaphore implementation
authorJonathan Wakely <jwakely@redhat.com>
Fri, 6 Jun 2025 13:16:15 +0000 (14:16 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 6 Jun 2025 19:15:07 +0000 (20:15 +0100)
The lambda expression causes testsuite failures such as:
FAIL g++.dg/modules/xtreme-header-2_b.C -std=c++26 (test for excess errors)

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h (_Select_semaphore_impl): Rename
to _Semaphore_impl and use std::conditional_t instead of an
immediately invoked lambda expression.
* include/std/semaphore (counting_semaphore): Adjust to use new
name.

libstdc++-v3/include/bits/semaphore_base.h
libstdc++-v3/include/std/semaphore

index ebbc9a80b91a986ea0befa89d986ef97debfb273..82871ce3518bbd340e55cb7658c6212be46dd637 100644 (file)
@@ -289,22 +289,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     alignas(__detail::__platform_wait_alignment) __count_type _M_counter;
   };
 
-  template<ptrdiff_t _Max>
-    using _Select_semaphore_impl = typename decltype([]
-    {
-      using namespace __detail;
-      if constexpr (__platform_wait_uses_type<__platform_wait_t>)
-       {
-         if constexpr (_Max <= 1)
-           return type_identity<__platform_semaphore_impl<true>>{};
-         else if constexpr (_Max <= __platform_semaphore_impl<false>::_S_max)
-           return type_identity<__platform_semaphore_impl<false>>{};
-         else
-           return type_identity<__semaphore_impl>{};
-       }
-      else
-       return type_identity<__semaphore_impl>{};
-    }())::type;
+  template<ptrdiff_t _Max, typename _Tp = __detail::__platform_wait_t>
+    using _Semaphore_impl
+      = __conditional_t<__platform_wait_uses_type<_Tp>
+                         && _Max <= __gnu_cxx::__int_traits<_Tp>::__max,
+                       __platform_semaphore_impl<(_Max <= 1)>,
+                       __semaphore_impl>;
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
index 8f49188563e8b806e3ab3262b124cf59dd31073e..18d04075776cd37546fb70bcb2f9ed1fb30d37be 100644 (file)
@@ -45,12 +45,12 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  template<ptrdiff_t __least_max_value = _Select_semaphore_impl<2>::_S_max>
+  template<ptrdiff_t __least_max_value = _Semaphore_impl<2>::_S_max>
     class counting_semaphore
     {
       static_assert(__least_max_value >= 0);
 
-      _Select_semaphore_impl<__least_max_value> _M_sem;
+      _Semaphore_impl<__least_max_value> _M_sem;
 
     public:
       constexpr explicit