Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pragma warning(push, 0) doesn't disable /Wall warnings?

I recall this trick working some time in the past, but it doesn't seem to be working now.

Putting #pragma warning(push, 0) around #include statements doesn't actually prevent /Wall warnings from being generated from those included files.

Changing /Wall to /W4 gets around the issue, but using /Wall seems to be broken.

#pragma warning(push, 0)

#include <iostream>

#pragma warning(pop)

int main() {
    std::cout << "Hello, World!";
}

Build output:

image

Microsoft Visual Studio Community 2017 Version 15.5.3

Full command line switches (generated from cmake):

/GS /TP /analyze- /Wall /Zc:wchar_t /Gm- /O2 /Ob2 /Fd"main.dir\Release\vc141.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "NDEBUG" /D "CMAKE_INTDIR=\"Release\"" /D "_MBCS" /errorReport:prompt /WX /Zc:forScope /GR /Gd /Oy- /MD /std:c++14 /Fa"Release/" /EHsc /nologo /Fo"main.dir\Release\" /Fp"main.dir\Release\main.pch" /diagnostics:classic 

I googled around and found a post that seems to describe the same issue, but no solution was suggested. Hopefully folks here on StackOverflow have a better idea?

like image 903
Jeff M Avatar asked Jan 23 '18 23:01

Jeff M


People also ask

What is pragma warning disable C#?

C# provides a feature known as the #pragma feature to remove the warnings. Sometimes we declare a variable but do not use the variable anywhere in the entire program so when we debug our code the compiler gives a warning so using the #pragma we can disable these types of warnings.

How do I enable warnings in Visual Studio?

If you want to turn it on (or off) in the project setting, you have to go to: Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter: /w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.


1 Answers

This appears to have been fixed for me in 15.9.1.

like image 160
pjcard Avatar answered Oct 04 '22 09:10

pjcard