[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers
JF Bastien via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 7 13:14:23 PDT 2018
jfb added a comment.
Herald added a reviewer: javed.absar.
I was just looking at this, and I think @arphaman's patch is pretty much the right approach (with 2 suggested fixes below).
I don't think the code we're currently warning on is broken: a user code has `NSInteger` with `%zd` or `NSUInteger` with `%zu`, and on all platforms which support those types the implementor has guaranteed that `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == sizeof(NSUInteger))`. I agree that, if we're playing C++ pedant and look at the typedefs, then it's undefined behavior and the code is broken. However the implementation provided more guarantees than C++ does through its platform typedefs so pendantry need not apply (or rather: clang should look no further than the typedef, and trust the platform in this particular case).
We of course should still warn on sign mismatch.
I don't think this should even be a warning with pedantic on: there's no portability issue at all because all OSes and architectures where this could ever fire are guaranteed to do the right thing.
Suggested fixes:
1. Don't compare `CastTyName` directly, instead recurse as `shouldNotPrintDirectly` does so `typedef` nesting is also handled.
2. Add a test that sign mismatched is still diagnosed.
If you all agree I'll post an updated patch.
Repository:
rC Clang
https://reviews.llvm.org/D42933
More information about the cfe-commits
mailing list