[PATCH] D132266: [Clang][SemaChecking] move %hh and %h -Wformat warnings to -Wformat-pedantic

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 22 10:00:17 PDT 2022


aaron.ballman added a comment.

In D132266#3740013 <https://reviews.llvm.org/D132266#3740013>, @inclyc wrote:

> If some one use `%hhd` with an unmatched type argument. Should we emit diagnose like
>
>   format specifies type 'int' but the argument has type 'WhateverType'
>
> instead of
>
>   format specifies type 'char' but the argument has type 'WhateverType'
>
> ?
>
> It's seems that there are many regression tests about this. Should we keep the legacy behaviour?

I think we want the diagnostic to identify the target type from the format specifier along with the actual and promoted type (if relevant) of the argument that mismatches. e.g.,

  float f = 1.0f;
  printf("%hd", f);

I would expect this to say something like `format specifies type 'short' but the argument has type 'double' (promoted from 'float')`.

This way users know 1) what the type of the source argument is without hunting for it, 2) what the target type of the format specifier is without hunting down what the specifiers mean, 3) what the actual mismatching type is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132266



More information about the cfe-commits mailing list