I would like to find out which is the most extreme error checking flag combination for g++ (4.7). We are not using the new C++11 specification, since we need to cross compile the code with older compilers, and these older compilers (mostly g++ 4.0) often cause problems which simply are ignored by the g++4.7.
Right now we use the following set of flags:
-Wall -Wcomment -Wformat -Winit-self -ansi -pedantic-errors \
-Wno-long-long -Wmissing-include-dirs -Werror -Wextra
but this combination does not identify issues such as a double being passed in to a function which expects int, or comparison between signed and unsigned int and this causes the old compiler to choke on it.
I have read through the documentation and -Wsign-compare
should be enabled by -Wextra
but in practice seems this is not the case, so I might have missed something...
Generate errors if code violates strict ISO C and ISO C++. If you use the -pedantic-errors option, the compiler does not use any language feature that conflicts with strict ISO C or ISO C++. The compiler generates an error if your code violates strict ISO language standard.
The -pedantic option tells GCC to issue warnings in such cases; -pedantic-errors says to make them errors instead. This does not mean that all non-ISO constructs get warnings or errors. See Options to Request or Suppress Warnings, for more detail on these and related command-line options.
Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don't interrupt the compilation process.
It's short for "warn all" -- it turns on (almost) all the warnings that g++ can tell you about.
The -ansi
is alias for the default standard without GNU extensions. I'd suggest instead being explicit using -std=c++98
, but it should be default for g++ -ansi
, so not really different.
But generally I've never seen anything that would be accepted by newer gcc and rejected by older gcc on the grounds of being invalid. I suspect any such problem is a bug in the older compiler or it's standard library. Gcc does not have warnings for things that are correct, but didn't work with older versions of it, so you don't have any other option than to test with the older version.
As for the specific issues you mention:
-Wconversion
should help.-Wno-sign-compare
.The compiler should not print warnings for headers found in directories given with -isystem
instead of -I
, so that should let you silence the warning for Qt headers and keep it enabled for your own code. So you should be able to use -Wconversion
.
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