Reputation: 147
I have enabled -Werror
for C pre processing command to treat warnings as errors.
Basically i wanted to only
treat redefined
warnings as errors. And all other warnings should not be treated as errors.
In file included from /home/test/version24/test.spec:35:0,
/test/release/base_version.spec:93:0: warning: "CD_MK_FILE" redefined
#define CD_MK_FILE 4
In file included from /home/test/version23/mss_litter.spec:19:0,
from
/test/release/base_version23.spec:0: note: this is the location of the previous definition
#define CD_MK_FILE 3
Is there any flag in to treat only redefined warnings as errors. Thank you!
Upvotes: 3
Views: 1904
Reputation: 52499
How to only treat macro-redefined
warnings as errors, and let all other warnings not be treated as errors:
-Werror=macro-redefined
.For gcc
/g++
and clang
compilers, try:
# To disable -Werror just for warning -Wwhatever
-Wno-error=whatever
# To **enable** errors just for this one -Wwhatever warning
-Werror=whatever
For the clang compiler, you'd use -Wno-error=macro-redefined
, to disable that error for the -Wmacro-redefined
warning only, and you'd use -Werror=macro-redefined
to enable an error only for that warning.
See here: https://clang.llvm.org/docs/DiagnosticsReference.html#wmacro-redefined. Thanks for the comment under the question, @user3386109!
See the list of all possible warnings and errors here:
For example, from the gcc link above:
-Werror=
Make the specified warning into an error. The specifier for a warning is appended; for example
-Werror=switch
turns the warnings controlled by-Wswitch
into errors. This switch takes a negative form, to be used to negate-Werror
for specific warnings; for example-Wno-error=switch
makes-Wswitch
warnings not be errors, even when-Werror
is in effect.The warning message for each controllable warning includes the option that controls the warning. That option can then be used with
-Werror=
and-Wno-error=
as described above. (Printing of the option in the warning message can be disabled using the-fno-diagnostics-show-option
flag.)Note that specifying
-Werror=foo
automatically implies-Wfoo
. However,-Wno-error=foo
does not imply anything.
-Werror
build error in Bazel? (AKA: how to turn OFF specific warnings already turned on by -Wall -Werror
)Upvotes: 4