Search code examples
visual-c++visual-studio-2015pragma

Visual C++ #pragma warning


I have the following three consecutive warnings:

Warning C4068 unknown pragma ...\microsoft visual studio 14.0\vc\include\comutil.h  53
... 54
... 54

The related lines are:

#pragma warning(push)
#pragma warning(disable: 4290)
#pragma warning(disable: 4310)

The Platform Toolset is the usual v140 and the Target Platform version is 8.1. The warning level is W3.

I read the current #pragma warning documentation.

As I understand the first line saves the current state of warning settings.
The following two lines disable the warnings 4290 4310 for the code ahead until a #pragma warning(pop) restores the previously saved state.

Why does #pragma warning appear as unknown?


Solution

  • In the project's Property Pages I set

    C/C++ -> Preprocess to a file -> Yes (/P)
    

    I rebuilt the project, which produced a Debug dir with a *.i file for each C++ file, containing all macros expanded (see here).
    The files are very large, but they also contain useful #line directives showing when the compiler accesses and exits from a header file. So I grepped for the name of the header file raising the error and I was able to detect that the warning in #pragma warning(push) had been expanded too, which caused the not found warning.

    Since I had included a number of headers from a third party GNU project (where this type of #pragma is not defined), it was relatively simple to find the #define warning macro raising the compiler warning.