Skip to content

Commit 4d7a8b1

Browse files
[libc] disable -Wtype-limits in wctob
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
1 parent d281941 commit 4d7a8b1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libc/src/__support/wctype_utils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ LIBC_INLINE cpp::optional<int> wctob(wint_t c) {
2929
// This needs to be translated to EOF at the callsite. This is to avoid
3030
// including stdio.h in this file.
3131
// The standard states that wint_t may either be an alias of wchar_t or
32-
// an alias of an integer type, so we need to keep the c < 0 check.
32+
// an alias of an integer type where different platforms define this type with
33+
// different signedness, so we need to keep the c < 0 check, hence the
34+
// pragmas.
35+
#pragma GCC diagnostic push
36+
#pragma GCC diagnostic ignored "-Wtype-limits"
3337
if (c > 127 || c < 0)
3438
return cpp::nullopt;
39+
#pragma GCC diagnostic pop
3540
return static_cast<int>(c);
3641
}
3742

0 commit comments

Comments
 (0)