I get this warning from GCC:
warning: cannot pass objects of non-POD type 'class Something' through '...'; call will abort at runtime
It's pretty deadly, especially since it calls an abort. Why isn't this an error? I would like to make it an error, but:
How do I make a specific warning an error?
Which warning is it? According to 3.8 Options to Request or Suppress Warnings, -Wno-invalid-offsetof, it looks like the flag to hide it, but it doesn't.
I'm not sure what the correct warning is, but once you've found it, you can change its disposition with the following (using 'format' as the example):
#pragma GCC diagnostic error "-Wformat"
Or as strager points out:
gcc -Werror=format ...
I've checked the gcc source for this and this specific warning cannot be disabled via command line flags.
-Werror=specific-warning will turn the specified -Wspecific-warning into an error in GCC 4.3.x or newer. In 4.1.2, only -Werror-implicit-function-declaration works. Note the hyphen instead of equals sign -- it works for that specific case only and no others. This is one of the more serious common warnings and it's definitely handy to make it into an error.
Apart from that, older versions of GCC only seem to provide the -Werror sledgehammer of making every last warning an error.
It sounds like there are a bunch of other warnings that you don't want to be turned into errors (using the -Werror flag). In general, it's good practice to fix all warnings. Using -Werror forces this.
You can use the -Werror compiler flag to turn all or some warnings into errors.
You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.
Unfortunately, in this case there isn't any specific option that covers that warning.
It appears that there will be better support for this in GCC 4.5.
Related
When using pFUnit (3.2.9) to test my Fortran code, I get many "Illegal preprocessor directive" warnings, e.g.
Warning: Illegal preprocessor directive
/path/to/my/file/test.f90:37:2:
#line 26 "/path/to/my/file/test.f90"
1
The code compiles and runs fine, so I would like to turn off these warnings, while still seeing other compiler warnings. Which gfortran compiler flag turns this specific warning off? I am working with gfortran 7.3.1.
This is not the kind of warning that one should turn off because not using a preprocessor has usually very bad consequences on codes that use the most common directives like #define and #if. And as far as I know it isn't possible to turn it off.
It is much wiser to enable the preprocessor using the -cpp flag. Not only the warnings will stop but you will get the correct line numbers in further diagnostics as well, the line numbers will refer to your original code.
In the Build Settings is it possible to treat Specific warnings as Error instead of Treating all warnings are Errors.
This is a simple Switch statement checker in xcode :
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES_Error
instead of :
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
But its not working for me.
Treat specific warnings as errors
use -Werror=
for example:
-Werror=unused-variable will treat unused variable as error, which originally treat as warning by -Wunused-variable flag
add these to Other Warning Flags in project setting.
Treat all warnings as errors except for some warnings
use -Werror and -Wno-error=
The first one will treat all warnings as errors, equals to the setting in Xcode.
And use -Wno-error= to make specific warning not be error. For example:
-Wno-error=unused-variable
add these to Other Warning Flags in project setting.
Reference https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
For all warning flags https://clang.llvm.org/docs/DiagnosticsReference.html
This link may work for you.
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html says
-Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.
Please check.
I am developing a BREW application. When compiling the application to get a MOD file, I am continuously getting this error:
cc1.exe: warnings being treated as errors
I want to disable this warning. I have googled it, and many say disabling -werror will help, but how can I do that?
The compiler is CodeSourcery ARM.
You need to remove -Werror from CFLAGS, CPPFLAGS etc.; these are usually set in Makefile's or build scripts.
However, I'd strongly advice to fix the actual warnings instead, which will produce more stable and error-free code.
Run this Command in Terminal to say, not to consider warning as error
make CFLAGS="-Wno-error=format-truncation"
I want to remove a compiler flag for a praticular file in my project. How to do this using #pragma?
Sorry that this is late, but I just ran into the same issue on my project.
I couldn't find a #pragma to modify the list of compiler flags, but I could use GNU Make's ability to modify make variables on a per-target basis.
One of my files was taking forever to compile with -fvar-tracking-assignments (which was added to -O2 a few releases back). I was looking for a way to turn that off for one file; after looking (in vain) for an appropriate pragma, I simply added this line to my makefile to modify CXXFLAGS when compiling and linking those specific files:
ObtuseObj.o ObtuseObjTest.o ObtuseObjTest : CXXFLAGS += -fno-var-tracking-assignments
Hopefully this will be helpful to others!
Only flags that control warnings can be overridden using #pragma, see the diagnostic pragmas documentation page.
For instance, you could do:
#pragma GCC diagnostic ignored "-Wformat"
To make GCC ignore the warnings generated by mismatched formatting strings.
I'm not sure if gcc has such pragmas. I can't find any on the gcc page for pragmas.
If you are asking a question related to gcc next time, tag it under gcc as well. I would tag it but I can't. Tagging under gcc would get you many more responses.
It's a part of larger code base, which forces -Werror on gcc. This warning is generated in a third party code that shouldn't be changed (and I actually know how to fix it), but I can disable specific warnings. This time man gcc failed me, so please, let some gcc master enlighten me. TIA.
It is the -Wno-unused-value option, see the documentation
If you use -fdiagnostics-show-option, GCC will tell you how to disable a warning (if possible).
Have you tried using a diagnostic pragma directive? These are available in gcc 4.2.1+, I believe.