[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 15 11:23:42 PDT 2019

aaron.ballman added a comment.

In D66186#1631921 <https://reviews.llvm.org/D66186#1631921>, @Nathan-Huckleberry wrote:

> 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.

This all makes sense as to how things work today, but I was more wondering why they worked that way in the first place. I'm especially interested to know whether this is diagnosed because it shows confusion of the user's intent, because that seems like a valuable behavior to retain (though perhaps it doesn't need to be default-on).

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list