From: Jonathan Wakely Date: Fri, 4 Oct 2024 17:11:06 +0000 (+0100) Subject: libstdc++: Fix -Wsign-compare in std::latch::count_down X-Git-Tag: basepoints/gcc-16~5344 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5021ce9aa6be524beca99e0bbd0180b4e53029b;p=thirdparty%2Fgcc.git libstdc++: Fix -Wsign-compare in std::latch::count_down 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. --- diff --git a/libstdc++-v3/include/std/latch b/libstdc++-v3/include/std/latch index 146e1860979..1d254aa2581 100644 --- a/libstdc++-v3/include/std/latch +++ b/libstdc++-v3/include/std/latch @@ -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