https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120449
--- Comment #6 from Zartaj Majeed <zmajeed at sbcglobal dot net> --- Thanks - the following works diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f71cb2652d5..6d7ef006c6a 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -3318,7 +3318,7 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr, warning. */ tree folded_op0 = fold_for_warn (op0); bool warn = - warn_type_limits && !in_system_header_at (loc) + warn_type_limits && diagnostic_report_warnings_p(global_dc, loc) && !(TREE_CODE (folded_op0) == INTEGER_CST && !TREE_OVERFLOW (convert (c_common_signed_type (type), ---------------- g++ -c -Wtype-limits -std=c++20 -Wsystem-headers typelimits.cpp In file included from requires_hosted.h:31, from semaphore:36, from typelimits.cpp:1: 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); | ^~~~~~~~~~~~~~~~ Though position of underline is off ---------------- Underline is wrong and confusing with --save-temps g++ -c -Wtype-limits -std=c++20 -Wsystem-headers --save-temps typelimits.cpp In file included from semaphore:39, from typelimits.cpp:1: semaphore_base.h: In constructor ‘std::__atomic_semaphore::__atomic_semaphore(std::__detail::__platform_wait_t)’: semaphore_base.h:178:47: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits] 178 | __glibcxx_assert(__count >= 0 && __count <= _S_max); | ~~~~~~~~^~~~ ---------------- Underline is correctly positioned with -P g++ -c -Wtype-limits -std=c++20 -Wsystem-headers --save-temps -P typelimits.cpp typelimits.ii: In constructor ‘std::__atomic_semaphore::__atomic_semaphore(std::__detail::__platform_wait_t)’: typelimits.ii:10140:47: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits] 10140 | do { if (__builtin_expect(!bool(__count >= 0 && __count <= _S_max), false)) std::__glibcxx_assert_fail("semaphore_base.h", 178, __PRETTY_FUNCTION__, "__count >= 0 && __count <= _S_max"); } while (false); | ~~~~~~~~^~~~