[libc-commits] [libc] [libc] disable -Wtype-limits in wctob (PR #74511)
via libc-commits
libc-commits at lists.llvm.org
Tue Dec 5 10:34:08 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Nick Desaulniers (nickdesaulniers)
<details>
<summary>Changes</summary>
GCC warns:
libc/src/__support/wctype_utils.h:33:20: error: comparison of unsigned
expression in ‘< 0’ is always false [-Werror=type-limits]
33 | if (c > 127 || c < 0)
| ~~^~~
Looking into the signedness of wint_t, it looks like depending on the platform,
__WINT_TYPE__ is defined to int or unsigned int depending on the platform.
Link: https://lab.llvm.org/buildbot/#/builders/250/builds/14891/steps/6/logs/stdio
---
Full diff: https://github.com/llvm/llvm-project/pull/74511.diff
1 Files Affected:
- (modified) libc/src/__support/wctype_utils.h (+6-1)
``````````diff
diff --git a/libc/src/__support/wctype_utils.h b/libc/src/__support/wctype_utils.h
index 6d825499a1b0f..367f5a86647fd 100644
--- a/libc/src/__support/wctype_utils.h
+++ b/libc/src/__support/wctype_utils.h
@@ -29,9 +29,14 @@ LIBC_INLINE cpp::optional<int> wctob(wint_t c) {
// This needs to be translated to EOF at the callsite. This is to avoid
// including stdio.h in this file.
// The standard states that wint_t may either be an alias of wchar_t or
- // an alias of an integer type, so we need to keep the c < 0 check.
+ // an alias of an integer type where different platforms define this type with
+ // different signedness, so we need to keep the c < 0 check, hence the
+ // pragmas.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
if (c > 127 || c < 0)
return cpp::nullopt;
+#pragma GCC diagnostic pop
return static_cast<int>(c);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/74511
More information about the libc-commits
mailing list