]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix -Wsign-compare in std::latch::count_down
authorJonathan Wakely <jwakely@redhat.com>
Fri, 4 Oct 2024 17:11:06 +0000 (18:11 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 9 Oct 2024 12:41:06 +0000 (13:41 +0100)
Also add assertions for the precondition on the parameter's value.

libstdc++-v3/ChangeLog:

* include/std/latch (latch::count_down): Add assertions for
preconditions. Cast parameter to avoid -Wsign-compare on some
targets.

libstdc++-v3/include/std/latch

index 146e1860979acf38889232ea553d6b21ad4ca600..1d254aa2581a7b1672a0e1a1cd2d844ffcc9c764 100644 (file)
@@ -63,9 +63,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _GLIBCXX_ALWAYS_INLINE void
     count_down(ptrdiff_t __update = 1)
     {
+      __glibcxx_assert(__update >= 0);
       auto const __old = __atomic_impl::fetch_sub(&_M_a,
                                    __update, memory_order::release);
-      if (__old == __update)
+      __glibcxx_assert(__update >= 0);
+      if (__old == static_cast<__detail::__platform_wait_t>(__update))
        __atomic_impl::notify_all(&_M_a);
     }
 
@@ -88,6 +90,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   private:
+    // This alignas is not redundant, it increases the alignment for
+    // long long on x86.
     alignas(__alignof__(__detail::__platform_wait_t)) __detail::__platform_wait_t _M_a;
   };
 _GLIBCXX_END_NAMESPACE_VERSION