I want to suppress specific warnings from g++. I'm aware of the -Wno-XXX
flag, but I'm looking for something more specific. I want some of the warnings in -Weffc++
, but not all of them. Something like what you can do with lint - disable specific messages.
Is there a built in way in gcc to do this? Do I have to write a wrapper script?
To suppress this warning use the unused attribute (see Variable Attributes). This warning is also enabled by -Wunused , which is enabled by -Wall . Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall .
You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).
Maybe you can look for CFLAGS options in Makefile and remove the -Werror flag. The Werror flag will make all warnings into errors. Show activity on this post. In general, it is not a good idea to ignore warnings from your compiler.
Unfortunately, this feature isn't provided by g++. In VC++, you could use #pragma warning to disable some specific warnings. In gcc, the closest you can have is diagnostic pragmas, which let you enable/disable certain types of diagnostics for certain files or projects.
Edit: GCC supports pushing/popping warnings since 4.6.4 (see changelog)
For some warnings, there is a command line switch to disable them. In order to know which switch to use, pass -fdiagnostics-show-option
to gcc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With