Skip to content

[libc] fix -Wtype-limits in wctob #74511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libc/src/__support/wctype_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ 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.
if (c > 127 || c < 0)
// an alias of an integer type, different platforms define this type with
// different signedness. This is equivalent to `(c > 127) || (c < 0)` but also
// works without -Wtype-limits warnings when `wint_t` is unsigned.
if ((c & ~127) != 0)
return cpp::nullopt;
return static_cast<int>(c);
}
Expand Down