2

I'm running Visual Studio 2017. I'm trying to add a Scripting Language called ChaiScript to my project, but it generates A LOT of warnings when I have /Wall on, and I also have treat warnings as errors on (I prefer this to stay like this).

So I figured I would try to temporarily disable all the warnings when including the ChaiScript header file (only need to include 1 file). At first I did this...

#pragma warning( disable : 4061 )
#pragma warning( disable : 4068 )
#pragma warning( disable : 4191 )
#pragma warning( disable : 4355 )
#pragma warning( disable : 4365 )
#pragma warning( disable : 4371 )
#pragma warning( disable : 4464 )
#pragma warning( disable : 4514 )
#pragma warning( disable : 4571 )
#pragma warning( disable : 4623 )
#pragma warning( disable : 4625 )
#pragma warning( disable : 4626 )
#pragma warning( disable : 4668 )
#pragma warning( disable : 4710 )
#pragma warning( disable : 4774 )
#pragma warning( disable : 4820 )
#pragma warning( disable : 5026 )
#pragma warning( disable : 5027 )
#include <chaiscript\chaiscript.hpp>

This works, I can compile... However, I then wanted to have these warnings re-enabled for the rest of the compile process.... So I turned it into this...

#pragma warning( push )
#pragma warning( disable : 4061 )
#pragma warning( disable : 4068 )
#pragma warning( disable : 4191 )
#pragma warning( disable : 4355 )
#pragma warning( disable : 4365 )
#pragma warning( disable : 4371 )
#pragma warning( disable : 4464 )
#pragma warning( disable : 4514 )
#pragma warning( disable : 4571 )
#pragma warning( disable : 4623 )
#pragma warning( disable : 4625 )
#pragma warning( disable : 4626 )
#pragma warning( disable : 4668 )
#pragma warning( disable : 4710 )
#pragma warning( disable : 4774 )
#pragma warning( disable : 4820 )
#pragma warning( disable : 5026 )
#pragma warning( disable : 5027 )
#include <chaiscript\chaiscript.hpp>
#pragma warning( pop )

Now I thought this would make it so it would compile the header without the warnings, then go back to checking for those warnings.... but it seems that after I do this... I still get 4 C4710 warnings... Am I doing something wrong?

https://i.imgur.com/RuxboQC.png

Rick
  • 353
  • 1
  • 16
  • Is there another area where you're including chaiscript? I assume you were warning free before you starting trying to include chaiscript? – Tas Nov 28 '17 at 21:13
  • Literally my program is just an empty .h file with the above code, and then a .cpp that includes that .h file. I just managed to get the errors down to 4 warnings, updated my post. So no, there isn't. – Rick Nov 28 '17 at 21:14
  • If inlining occurs at link time, how the linker chooses to interpret `#pragma warning` may be non-intuitive. For example, linking comes well after your source files (include this header) are compiled. At that time, `#pragma warning( pop )` has been found and compiled. Though I'm not sure when VS chooses to preform inlining. – François Andrieux Nov 28 '17 at 21:32
  • I think I've concluded this might be a VS2017 bug... If I have the disable outside of the push for C4710, it works... – Rick Nov 28 '17 at 21:37

2 Answers2

1

Add a #pragma warning(push, 3) before all the disables and a #pragma warning(pop) after the include.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
0

In this particular case, the problem is likely that, although the warning was disabled when compiling the function definition, it was re-enabled where the compiler had the option of inlining it. There doesn't seem to be a practical solution to that.

Microsoft lists the warnings that are off-by-default. The difference between /W4 and /Wall is that /Wall enables the off-by-default warnings. The off-by-default warnings are off-by-default because they are either low value and/or because you'd likely get many false positives. It might be instructive to occasionally check your project with /Wall to see if there's any useful information in there, but it doesn't seem practical to have them enabled all the time.

I'm a huge fan of pushing the warning level as high as is practical, but /Wall is a step too far for me. I recommend /W4 with /WX everywhere. If necessary for third-party code, drop down to /W3 using #pragma warning(push/pop) as you've shown. In my experience, all the Microsoft headers compile cleanly at /W4.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175