Schmorp's POD Blog a.k.a. THE RANT a.k.a. the blog that cannot decide on a name

Tidbits: For the love of god, don't use -Werror!

Ok, a disclaimer first: I neither believe in any god (the title is a figure of speech), nor do I ask you to not use -Werror . Yeah, right, so what the heck?

How to use and not use compiler warnings

There is a common complaint about my software - some compilers sometimes emit warnings when compiling some code, which some people sometimes find somewhat offensive.

The reason I might not care is because warnings are just that - warnings. They aren't errors, they do not necessarily indicate a bug. They can be very useful though, which is why I investigate the ones I know of.

But, and that's what some complainers might forget, different compilers and different compiler versions (on different platforms, even) have different warnings (wow there's a lot of only semi-intended alliteration going on today).

Or in other words, your compiler might emit a warning that my compiler didn't. Or my compiler emits a warning that it didn't emit before I upgraded today. Sometimes, a compiler warning is simply wrong (or easy to misinterpret) and impossible to work around, so you can't even do anything about it.

In short, compiler warnings are no magic bullet - you still have to know what you are doing, you still have to understand what the warning really says.

But if you do, warnings are an indispensable tool to weed out bugs, so by all means, use them on your own code.

How to definitely not use compiler warnings: -Werror

Now, some people (and I feel this group is growing) are going a step too far, by enabling -Werror unconditionally in their software packages. And what applies to me - not being able to anticipate warnings in other compilers - of course applies to them as well.

This is disastrous, because it almost guarantees that your software won't compile on my system, and I have to go hunting in your configure script or custom Makefile rules on where it is enabled. Or more general, this forces people who want to compile your software to patch its build system - not a good start.

Two recent examples are squid and qemu-linaro , two packages I had to compile from source as Debian GNU/Linux didn't have (good enough, or any) packages for them.

Both enable -Werror , and both fail to compile because of that. Even though I use the same compiler suite as them (GCC), I often have slightly newer versions (as a no-longer coding member of the GCC steering committee I am trying to keep up with new developments), and sometimes have older versions as well, just for fun.

squid requires me to doctor around in its configure script, and even patch some Makefiles , while qemu-linaro has a central location for it.

Both are no fun to fix.

TL;DR

Enabling -Werror in distributions virtually guarantees that they won't build: Even if you took care of all compiler warnings in all compilers for which you enable this switch, it's just a question of time till a new compiler version comes along that has a new warning message and - BOOM. You can only gain extra disaster points by combining it with -Wall .

So don't do that in anything you ship, if you want others to build your stuff. Thank you.

Further reading

This posting has generated considerable and thoughtful discussion on hackernews: https://news.ycombinator.com/item?id=12155223.

Another blog post having a different rationale, but coming to pretty much the same conclusion: https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/.