[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers
Shoaib Meenai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 8 15:27:05 PDT 2018
smeenai added a comment.
In https://reviews.llvm.org/D42933#1092048, @rjmccall wrote:
> 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.
Apple's current recommendation for using printf with the NSInteger types is casting to a long, per https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html. Are you suggesting that recommendation would change to using `%zd` instead?
Repository:
rC Clang
https://reviews.llvm.org/D42933
More information about the cfe-commits
mailing list