1

But I want to use it with "Warnings treated as errors" = Yes

There seems to be a lot of useful check in the compiler flag but it isn't compatible with the standard headers. I want to use this compiler flag to check my code, but not the std headers. Is there a way to do this?

Or just disable warnings for any code I didn't write?

Edit:

Added pictures of the settings in visual studio and an example of what happens when I try to build. With just including iostream!

Example when trying to compile a basic C++ program with these settings

Community
  • 1
  • 1
  • I do not think it is. But warnings as errors goes too far IMO. Enough if you do not ignore them – 0___________ Aug 08 '17 at 22:53
  • " it isn't compatible with the standard headers" - in what sense? Give an example. –  Aug 08 '17 at 23:05
  • I added a picture to show what happens when you include and try to compile a C++ program. –  Aug 08 '17 at 23:19
  • Yes, I can absolutely confirm that when switching on the highest warning level (/Wall) you'll get entirely overwhelmed by the warnings coming from the STD headers, distributed within MSVC (that's a pity). And as I also like to use "warnings as errors", I generally use "/W4 /WX" and further disable some additional warnings (e.g. C4503 which happens frequently with templates). The situation is actually somewhat better now than in the past, the STL in MSVC 6.0 was not playing well even with /W4 and had to use /W3 instead. – EmDroid Aug 08 '17 at 23:29
  • @axalis Can I just disable warnings for any code I didn't write? –  Aug 08 '17 at 23:33
  • I would suggest to either use level 3 and add some level 4 warning or if tou really want level then disable warning you don't care. I think that level 4 goes to far and raise warning for perfectly correct code... and sometime, it is not easy to remove the remaining warning or the resulting code is worst than the original code. – Phil1970 Aug 09 '17 at 01:05

1 Answers1

2

You can disable the warnings in the headers (or change warning level for them) by changing the warning level before each inclusion, see here: How to suppress warnings in external headers in Visual C++. However that is not so handy because it needs to be done for every inclusion.

However if you'd use precompiled headers (which might be actually good for compilation speed), you can put all the system/STL headers you care about into the precompiled header file, and disable them via pragmas just there. Or you would need to create wrappers for the standard headers where you'll disable the warnings and include the wrapper headers instead.

And as discussed, the "/Wall" sometimes goes too far (e.g. the padding is quite usual thing you sometimes even can't do anything about), and even with the "/W4" the documentation mentions that it might be too detailed (however at the same time recommends it for new projects, so I generally use "/W4 /WX" for new projects). However some of the "/Wall" warnings still might find subtle bugs (like missing case in switch etc.). You might as well enable just some of the extra warnings selectively.

EmDroid
  • 5,918
  • 18
  • 18