← Back to context

Comment by o11c

6 days ago

In case anyone needs to do the sort of "fix up scattered declarations and move them to headers", you really want to use:

  gcc -Werror=missing-declarations -Werror=redundant-decls

(last I checked, Clang's implementation of this was buggy and half-useless, but I'll admit I stopped using Clang)

I recommend this for well-maintained code too, just as another way to keep the code smells away. For a lot of projects this will only require adding a bit of `static` that you were too lazy to write.

I suggest -Wall -Werror for code hygiene.

  • 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).