[libc-commits] [libc] [libc] disable -Wtype-limits in wctob (PR #74511)

via libc-commits libc-commits at lists.llvm.org
Tue Dec 5 11:12:05 PST 2023


================
@@ -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)
----------------
michaelrj-google wrote:

given how simple the condition is, it's cleaner often faster to let the compiler do that sort of optimization. In this specific case, they actually both get compiled to the same result: https://godbolt.org/z/f1E8beTch

https://github.com/llvm/llvm-project/pull/74511


More information about the libc-commits mailing list