Clang apparently adds some default flags to every run, and sometimes these take precedence over user-specified flags.
For example, I compiled the following program with clang -Wgnu main.c:
/* main.c */
int main(int argc, char *argv[]) {
const int foo = 42;
switch (argc) { case foo: return 5; }
return 0;
}
Using foo in the switch case is illegal because it isn't a constant expression, but gcc has a feature so that it is. The -Wgnu flag enables warnings when any of these GNU features are used, including the one being used here: constant folding (-Wgnu-folding-constant).
I expected to see the warning, "expression is not an integer constant expression; folding it to a constant is a GNU extension". However, I don't see any warning at all, despite passing the -Wgnu flag. Even with the -Weverything flag, the warning still does not show.
Only when explicitly specifying the -Wgnu-folding-constant flag does the warning show, which sort of defeats the purpose of having -Wgnu at all.
Running clang with the verbose flag (-v) sheds more light on the issue (large portions of uninteresting output elided):
$ clang -v -Wgnu main.c
Apple clang version 13.1.6 (clang-1316.0.21.2.3)
Target: arm64-apple-darwin21.4.0
...
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple arm64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all ... -v ... -Wgnu -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant ... -x c main.c
...
The output above shows the final command being passed to the frontend. You can find the -v and -Wgnu injected amidst a bunch of ceremony, and you'll also notice that eventually following the -Wgnu is a -Wno-gnu-folding-constant, the culprit for why this particular warning is hidden.
If you specify -Wgnu-folding-constant, the disable mysteriously disappears from the end of the command.
I'd like to know where these default flags are coming from, and how to disable them if possible.