[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 25 08:30:25 PDT 2024


AaronBallman wrote:

> > Can you also add a test showing the difference between `-Wformat -Wformat-signedness` and `-Wformat-signedness` by itself (which does nothing)?
> 
> With the current implementation `-Wformat-signedness` by itself actually turn on the signedness warnings. This is not compatible with how gcc do it. I guess I have thought that it was not that important to be compatible with gcc in this respect. However if it is I guess this could be implemented.

Personally, I find GCC's behavior a bit surprising, so I'm okay with a divergence there. But we should have tests for this just the same:

* `-Wformat-signedness`
* `-Wformat-signedness -Wno-format`
* `-Wno-format -Wformat-signedness`

The first test helps demonstrate that we intentionally deviate from GCC, but it also helps show whether `-Wformat-signedness` implies `-Wformat` or not. The second test helps answer whether `-Wformat-signedness` is turned off by disabling `-Wformat`. The third test helps answer whether format signedness can be turned on while turning off all other formatting warnings -- this test may not be needed if `-Wformat-signedness` by itself enables only the signedness diagnostics.

> > I'd also like to see a test demonstrating that `#pragma GCC diagnostic ignored -Wformat` disables the signedness warnings.
> 
> There is a single test in the end of clang/test/Sema/format-strings-signedness.c that demonstrate this.

Ah thank you!

https://github.com/llvm/llvm-project/pull/74440


More information about the cfe-commits mailing list