[llvm] [Support] [CMake] Only pass -Wno-c99-extensions to Clang, not GCC (PR #221822)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 7 23:42:28 PDT 2026


mstorsjo wrote:

> Interesting GCC behavior...
> 
> ```
> % echo 'int main() {}' | gcc -c -Wno-xxxx -pedantic -xc -
> % echo 'void main() {}' | gcc -c -Wno-xxxx -pedantic -xc -
> <stdin>:1:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
> cc1: note: unrecognized command-line option ‘-Wno-xxxx’ may have been intended to silence earlier diagnostics
> ```

Yes... On one hand, the behaviour does make sense (asking the compiler to not emit warnings for something it doesn't know is a no-op, it never would emit such warnings), but it means that if you want to check and optionally add a `-Wno-<foo>` option, you need to check whether `-W<foo>` is supported instead, and only then add `-Wno-<foo>`, which can be a little surprising (and requires everybody who adds such checks to know about it).

This used to be how we did most of these options (so there was lots of prior art to point towards), but in 4feae05c6abda364a9295aecfa600d7d4e7dfeb6 we changed many of those checks into static checks for compiler id/version, to speed up the cmake configure times.

If we'd be doing more of this kind of checks in the future, we perhaps could use a cmake helper function, like `check_add_warning_disable(-Wno-<foo>)`.

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


More information about the llvm-commits mailing list