ryao 6 days ago

I suggest -Wall -Werror for code hygiene.

1
o11c 5 days ago

I recommend against global -Werror, instead use -Werror= with each individual option to make it much easier to deal with compiler upgrades that change warnings.

For well-maintained code, -Werror=all is expected, but switching to it is not trivial in a nasty codebase. It's still worth doing, but it's a whole project.

-Werror=extra is also a good idea once your codebase is clean for all of the above, but you will need to learn to write suppressions, and some of those are compiler-specific.

-Werror=format=2 (requires adding attributes) and -Werror=unused (weird version-dependent interactions with other warnings, so better enable it explicitly) are next, then there's a long tail of obscure warning options that should be considered; many are useful but others should be explicitly disregarded (one particular question of interest that stick out: how hard is it to suppress/restore this within a macro).

Past the trivial, Clang's warnings tend to suck (and they often refuse patches even for parity); GCC's are more useful due to the strength of history. It's still worth using Clang just for the fact that it uses different logic for triggering warnings (and also different warnings available; -Weverything is great for discoverability); just be aware that `__has_warning` isn't very useful (what we really need is `__has_warning_that_actually_works_correctly`, which requires hard-coding known-bug-free compiler versions).