https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120472
Bug ID: 120472
Summary: Wtype-limits warning in semaphore_base.h on Cygwin
Product: gcc
Version: 15.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: zmajeed at sbcglobal dot net
Target Milestone: ---
This is a follow-up to bug 120449,
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120449
__platform_wait_t is unsigned long on Cygwin and causes type-limits warning in
semaphore_base.h
Testfile typelimits.cpp
#include <semaphore>
-----------------
With the fix from bug 120449
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120449#c6
g++ -c -Wtype-limits -std=c++20 -Wsystem-headers typelimits.cpp
In file included from libstdc++-v3/include/bits/requires_hosted.h:31,
from libstdc++-v3/include/semaphore:36,
from typelimits.cpp:1:
libstdc++-v3/include/bits/semaphore_base.h: In constructor
βstd::__atomic_semaphore::__atomic_semaphore(std::__detail::__platform_wait_t)β:
semaphore_base.h:178:7: warning: comparison of unsigned expression in β>= 0β is
always true [-Wtype-limits]
178 | __glibcxx_assert(__count >= 0 && __count <= _S_max);
-----------------
Warning could be fixed with something like
__glibcxx_assert((__count > 0 || __count == 0) && __count <= _S_max);
or also check for unsigned type
__glibcxx_assert((is_unsigned_v<decltype(__count)> || __count > 0 || __count ==
0) && __count <= _S_max);