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

Nathan Huckleberry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 11:05:22 PDT 2019


Nathan-Huckleberry added a comment.

In D66186#1630427 <https://reviews.llvm.org/D66186#1630427>, @aaron.ballman wrote:

> There was a request in the linked bug for some code archaeology to see why this behavior exists in the first place. What were the results of that? I'm not opposed to the patch, but I would like to understand why it behaves the way it does.


Since printf is a variadic function, integral argument types are promoted to int. The warning code runs the matchesType check twice, once to check if the promoted type (int) is able to be printed with the format and once to check if the original type (char) is able to be printed with the format.

`printf("%d", [char])` is caught by the first case
`printf("%hhd", [char])` is caught by the second case.

`printf("%hd", [char])` is a warning because an exception has not been made for that case.


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