Reputation: 4219
I am wondering if it is possible to have werror in gcc/g++ exclude certain files (ones that I do not have source code to modify) so that I can continue using werror in a uninhibited state.
Upvotes: 4
Views: 2580
Reputation: 4462
@Sam Miller already gave the reference documentation about how to do this...
You can temporarily disable -Werror
on certain warnings with #pragma GCC diagnostics warning "-W<kind>"
. For example:
#pragma GCC diagnostic push
# pragma GCC diagnostic warning "-Wreturn-type"
# pragma GCC diagnostic warning "-Wmissing-braces"
# include "legacy-crap.h"
#pragma GCC diagnostic pop
Newer gcc
will print the name of the diagnostics category in brackets as part of the the warning/error:
warning-test.c:11:1: warning: return type defaults to ‘int’ [-Wreturn-type]
or
warning-test.c:11:1: error: return type defaults to ‘int’ [-Wreturn-type]
This can be used to accurately select the exact diagnostics which should be treated as warning instead of error during processing of the third party crap you have no power to change. I do not know a short hand to disable all the warnings ("-Wall"
will not have desired effect for the above #pragma
), but I think it is also good to be explicit here.
Upvotes: 1
Reputation: 24174
Use pragma directives with a newer (4.2 I think) version of gcc to turn off -Werror for certain headers prior to including them.
You might want to accept answers for your previous questions.
Upvotes: 3
Reputation: 12397
My only thought is to compile the files you can modify separately with -Werror
and then link them with the other object/library files without -Werror
.
Upvotes: 0