views:

167

answers:

1

I usually like to have a lot of warnings enabled when programming. However, some libraries contains code that easily causes warnings (.., python, Qt, ..). When compiling with gcc I can just use -isystem instead of -I to silence that. How can I do the same with the MS compiler? I know of the warning #pragma, but I would like a solution that does not involve compiler specific code all over the place. I also know that I can turn off specific warnings, but that is not what I want either.

BTW: isystem should be a tag of this question, but I was not allowed to do that..

SUMMARY: I want to see all warnings from my code, and no warnings from external code.

A: 

look at the output output from cl /? :

/wd disable warning n

/we treat warning n as an error

/wo issue warning n once

/w set warning level 1-4 for n

Note that this disables the warnings for your entire project; I remember when using Qt I'd rather change it's main header with the #pragma warning disable and enable at the end again so I could still see all warnings for my own source.

Edit the author edited his question, updated answer: there is no way to get your code with warnings and Qt code without warnings using sompiler flags: how are you going to tell the compiler what is 'your' code?

Note that the above flags can be applied at file level as well, so this would allow you to disable the warnings for only those files in which you include Qt headers, but that still means you cannot see them for your own code in that files.

So I stay with the answer above; it is not quite pretty, but I'm pretty sure it's the only way: use #pragma at the beginning and the end of the Qt header(s). Either change the Qt headers (even more ugly), or choose a less invasive way like this:

  //your source/header file
#include "shutuppqt.h"
#include <QString>
#include "enableallwarnings.h"

example "shutuppqt.h"

#ifdef MSVC
  #pragma warning ( disable : 4222 ) //or whatever warning Qt emits
#else
  //....
#endif

example "enableallwarnings.h"

#ifdef MSVC
  #pragma warning ( enable : 4222 ) //or default instead of enable
#else
  //....
#endif
stijn
part 1:Hi, thanks for your answer! I just edited the question to clarify what i meant.You can actually use #pragma to push/pop warning level to 0 just when including the problematic headers, but that is not what I am looking for. That way you will get warnings for the rest of the file. A perfect solution, except that I want to do it without altering any code. (I can actually not understand that this is not a common thing to want.) All I want to do is make portable code and test it in different environments without putting in separate preprocessor logic for every compiler out there.
Mathias
part 2:Look at -isystem here:http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Preprocessor-Options.html#Preprocessor-OptionsBy using that option you effectively disable all warnings from any files in *dir*. That is how you tell the compiler what is you code, or more important; what is *not* your code.
Mathias
there is no such option for cl, or at least not a documented one... "I can actually not understand that this is not a common thing to want" -> well I can not understand that a big project like Qt does not take care of gettng rid of the tons of warnings it produces.
stijn
Yes I agree on that, but Qt was only an example. Right now crypto++ and python also spits out warnings. And with an uncountable number of libraries out there and dozens of compiler/compiler versions, warnings is bound to happen.
Mathias
true.. but as long as not all compilers support flags like this you have to deal with the warnings after all, either in the code, or in the compiler output.
stijn