问题
The following code does NOT suppress ANY C4503 compiler warnings, but it does suppress C4244 warnings.
#pragma warning(push)
#pragma warning(disable:4503)
#pragma warning(disable:4244)
#include <map>
#include <string>
int main(int argc, char *argv[])
{
class Field;
typedef std::map<std::string, Field * > Screen;
typedef std::map<std::string, Screen> WebApp;
typedef std::map<std::string, WebApp> WebAppTest;
typedef std::map<std::string, WebAppTest> Hello;
Hello MyWAT; // The C4503 error is NOT suppressed
int a;
a = 5.0f; // The C4244 error is suppressed
}
#pragma warning(pop)
Please definitively explain why C4503 warnings are not suppressed. Note: it might be due to a similar reason as referenced in How can I work around warning C4505 in third party libraries?.
See this and this for more relevant infornation.
I'm using Visual Studio 2008 on a Windows 7 machine.
回答1:
Not clear from the context, but maybe you have too many #pragma
statements? MSDN says:
The compiler only supports up to 56 #pragma warning statements in a compiland.
回答2:
Bit weird but you can disable this warning using your exact code just by removing the #pragma warning(pop)
. I don't understand why though.
I should say I'm on VS2010 C++ Express edition.
回答3:
Maybe stating the obvious but you can use the IDE settings to remove this (and other) warning(s) entirely, as explained here.
That was the only solution that worked for me, and was justified after learning that Boost has warning enable/disable policies built within, which alter the behavior of #pragma push/pop/enable/disable statements.
来源:https://stackoverflow.com/questions/9673504/is-it-possible-to-disable-compiler-warning-c4503