Issue 83271
Summary The -Wformat=2 flag should enable all -Wformat diagnostics similar to GCC
Labels
Assignees
Reporter thomasnyman
    The behavior between `-Wformat=2` flag in Clang and GCC differ in a way which may cause users to inadvertently miss out on wanted diagnostics messages:
- In GCC, the `-Wformat=2` flag [is equivalent to](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wformat_003d2) `-Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k`.
- In Clang, `-Wformat=2` [is equivalent to](https://github.com/llvm/llvm-project/blob/680c780a367bfe1c0cdf786250fd7f565ef6d23d/clang/include/clang/Basic/DiagnosticGroups.td#L987) `-Wformat-nonliteral -Wformat-security -Wformat-y2k` 

While `-Wformat` in Clang includes the same diagnostics as `-Wformat=2` the difference in the behavior of `-Wformat=2` between the compilers [makes it problematic to make recommendations on the use of warning flags](https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++#enable-additional-format-function-warnings) that would be consistent between Clang and GCC as `-Wformat` provides a superset of diagnostics in Clang, but `-Wformat=2` provides the superset of diagnostics in GCC.

Consequently it would be better if the behavior of `-Wformat=2` in Clang could be changed to also include the diagnostics flags implied by `-Wformat`.

Link to a test case in Compiler Explorer that demonstrates the difference in behavior with the different combinations of options: https://godbolt.org/z/nvocaaehY
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to