[PATCH] D66186: [Sema] Don't warn on printf('%hd', [char]) (PR41467)

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 14:00:18 PDT 2019


aaron.ballman added inline comments.


================
Comment at: clang/test/Sema/format-strings-enum-fixed-type.cpp:82
 
   // This is not correct but it is safe. We warn because '%hd' shows intent.
+  printf("%hd", input);        // no-warning
----------------
aaron.ballman wrote:
> This comment is now incorrect.
Not quite what I had in mind. I would remove the `// no-warning` comments that were added and instead change the comment on line 82 to say `This is not correct, but it is safe. Only warned in pedantic mode because '%hd' shows intent.` or something along those lines.


================
Comment at: clang/test/Sema/format-strings.c:280-281
   printf("%hhu", (short) 10); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
-  printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'unsigned char'}}
-  printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'uint8_t'}}
+  printf("%hu\n", (unsigned char)1); // no-warning
+  printf("%hu\n", (uint8_t)1);       // no-warning
 }
----------------
I'd drop the `no-warning` comments here, or say `warning with -Wformat-pedantic only` if you think it adds value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66186/new/

https://reviews.llvm.org/D66186





More information about the cfe-commits mailing list