What's Up with the Thousands of Warnings in Standard Headers in Msvc -Wall

user warnings on msvc AND gcc?

The best solution I've found for this problem is to have the following in a common header:

// compiler_warning.h
#define STRINGISE_IMPL(x) #x
#define STRINGISE(x) STRINGISE_IMPL(x)

// Use: #pragma message WARN("My message")
#if _MSC_VER
# define FILE_LINE_LINK __FILE__ "(" STRINGISE(__LINE__) ") : "
# define WARN(exp) (FILE_LINE_LINK "WARNING: " exp)
#else//__GNUC__ - may need other defines for different compilers
# define WARN(exp) ("WARNING: " exp)
#endif

Then use

#pragma message WARN("your warning message here")

throughout the code instead of #warning

Under MSVC you'll get a message like this:

c:\programming\some_file.cpp(3) : WARNING: your warning message here

Under gcc you'll get:

c:\programming\some_file.cpp:25: note: #pragma message: WARNING: your warning message here

Not perfect, but a reasonable compromise.

warning C4350: behavior change when including string and no precompiled header

Microsoft answered my question here:

http://connect.microsoft.com/VisualStudio/feedback/details/767960/warning-c4350-behavior-change-when-including-string-and-no-precompiled-header

Summary:

Is this a Visual Studio 2012 bug in std:string?
-They don't count it as a bug if if cleanly builds at warning level 4, which excludes this warning

Why does the precompiled header change the behavior?
-The compiler ignores everything that comes before a precompiled header, which in this case was my pragma statement that was enabling the warning. Enabling precompiled headers in the property settings caused the pragma to be ignored. Who knew?

How do I fix the problem, as opposed to just ignoring the warning?
-No fix it would seem, just ignore the warning

Compilation errors: Windows API headers.... broken?

Solved.

The problem was, the MinGW inclusions somehow ended up in the MSVC directory, making the compiler use those instead. Since they are Unix (POSIX) headers, the MSVC compiler can not compile them, and instead throws an exceptionally long list of errors. To solve this mess, I had to delete all the non-MSVC headers from the inclusion folders. The reason simple uninstall&reinstall didn't work is because MS uninstaller is file-specific and leaves all the non-original files in the directory. Visual Studio doesn't have, in fact, any Windows API header in the inclusion folder, and should be using the ones coming with Windows SDK.

So, since I've seen many people with this problem but no solutions to it, I'll leave the simplest answer here:
In order to clean up the folder from anything not needed, you have to uninstall everything first, then manually delete those folders, and finally reinstall everything. There might be more subtle solutions that would be better if you have many additional libraries installed (I had, in fact, some) and want to delete only the specific faulting headers, leaving the rest, but I don't really know how. If anybody knows of someway to do that, like maybe a tool that checks for MSVC-compatible headers and libraries, please let me know!


EDIT:
Additionally it may occur (at least in my case happened) that the VS SP1 gets also corrupted in the process, thus leading to compiler errors such as:

LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

To solve this, refer to the solutions given in this question.

How to correctly use code analysis in Visual Studio 2010 for C++?

You can disable code analysis warnings for header files that aren't PREfast clean with the warning() #pragma:

#include <codeanalysis\warnings.h>
#pragma warning(push)
#pragma warning (disable: ALL_CODE_ANALYSIS_WARNINGS)

// include headers

#pragma warning(pop)

Disable Qt warnings in Visual Studio 2008

I found only one way to do this: touch almost every Qt header file and include #pragma warning(push, 0) and #pragma warning(pop) at the right positions. I tried this once but gave up when the next Qt version was published.

Another possibility to reduce warnings is to disable specific warnings in the correct qmake.conf file (e.g. in mkspecs\win32-msvc2010).

I have changed some lines in this file:

QMAKE_CFLAGS_WARN_ON    = -W4 -w34100 -w34189 -wd4127 -wd4512
QMAKE_CFLAGS_RELEASE = -Ox -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -Ox -MD -Zi
QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON

How do I exclude library headers from my Visual Studio static code analysis?

You can disable all code analysis warnings for a particular block of code using #pragma warning in your code. MSDN provides the following example:

#include <codeanalysis\warnings.h>
#pragma warning( push )
#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS )
#include <third-party include files here>
#pragma warning( pop )

(See "How to: Enable and Disable Code Analysis for Specific C/C++ Warnings" for more information.)

To the best of my knowledge, there is no way to disable warnings from particular header files using only command line options.

Detecting superfluous #includes in C/C++?

It's not automatic, but doxygen will produce dependency diagrams for #included files. You will have to go through them visually, but they can be very useful for getting a picture of what is using what.

How can I disable warnings from non project files? --- Visual Studio 2010

  • You can also try;
  • #pragma warning(disable : xxxx)
  • Where xxxx represent the warning number i.e 4000 or 8010


Related Topics



Leave a reply



Submit