[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 8 15:12:48 PDT 2018


rjmccall added a comment.

I agree that the format-specifier checker is not intended to be a portability checker.

Any attempt to check portability problems has to account for two things:

- Not all code is intended to be portable.  If you're going to warn about portability problems, you need some way to not annoy programmers who might have good reason to say that they only care about their code running on Linux / macOS / 64-bit / 32-bit / whatever.  Generally this means splitting the portability warning out as a separate warning group.
- There are always established idioms for solving portability problems.  In this case, a certain set of important typedefs from the C standard have been blessed with dedicated format modifiers like "z", but every other typedef in the world has to find some other solution, either by asserting that some existing format is good enough (as NSInteger does) or by introducing a macro that expands to an appropriate format (as some things in POSIX do).  A proper format-portability warning would have to know about all of these conventions (in order to check that e.g. part of the format string came from the right macro), which just seems wildly out-of-scope for a compiler warning.


Repository:
  rC Clang

https://reviews.llvm.org/D42933





More information about the cfe-commits mailing list