Compiler warnings generally provide useful hints for common programming errors. It is often recommended to turn compiler warnings into errors (e.g. here). In my experience, this is useful to prevent warnings from getting ignored, especially on larger code bases or in automated build systems. However, some warnings are useful as warnings and cannot be turned into errors, either because they can happen to be false positives or because the code base cannot be adapted at once but it takes some transition period.
As a workaround, I could compile the same code twice:
-Wextra
), but without turning them into errors (i.e., without -Werror
)-Werror
command line option)This way the code project would benefit from more warnings than it could currently fix.
Is there a way to do this directly, i.e., with a single compilation step, not two?
I have read some mentions of the -Wno-error=[name]
option in another question and it barely mentioned in the latest clang command line reference, but I lack details. In case those provide a solution for my question, can you please elaborate what it does and/or provide a link to where it is documented?
From the documentation:
-Werror=foo
to turn warning "foo" into error,
-Wno-error=bar
to turn warning "bar" into warning even with -Werror
.
Now you have to browse the warnings list to select the ones you want to treat specifically.