Search code examples
c++visual-studiovisual-studio-2013warningspragma

pragma warning( disable : 4700 ) not working in Visual Studio Express 2013


Compiling the following code in Release configuration with SDL checks disabled:

#include <immintrin.h>

int main()
{
    const auto Set128Epi16 = []()
    {
#ifdef NDEBUG
#pragma warning( push )
#pragma warning( disable : 4700 )
            __m128i x = _mm_cmpeq_epi16( x,x );
            x = _mm_srli_epi16( x,15 );
            return _mm_slli_epi16( x,7 );
#pragma warning( pop )
#else
            __m128i x = _mm_setzero_si128();
            x = _mm_cmpeq_epi16( x,x );
            x = _mm_srli_epi16( x,15 );
            return _mm_slli_epi16( x,7 );
#endif
    };

    const auto xmm = Set128Epi16();

    return *xmm.m128i_i32;
}

Gives the following output:

1>------ Rebuild All started: Project: pragmatic, Configuration: Release Win32 ------
1>  main.cpp
1>  Generating code
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>  Finished generating code
1>  pragmatic.vcxproj -> E:\Projects\pragmatic\Release\pragmatic.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Why is the compiler ignoring my #pragma in this case. I have in the past successfully used this method to suppress the same warning code.


Solution

  • I copied this from https://msdn.microsoft.com/en-us/library/2c8f766e.aspx

    For warning numbers in the range 4700-4999, which are the ones associated with code generation, the state of the warning in effect when the compiler encounters the open curly brace of a function will be in effect for the rest of the function. Using the warning pragma in the function to change the state of a warning that has a number larger than 4699 will only take effect after the end of the function. The following example shows the correct placement of warning pragmas to disable a code-generation warning message, and then to restore it.

    So you probably need to put the pragma before the start of main, or maybe before the lambda would work, but I'm not sure about that.