pragma 警告(禁用:4700)在 Visual Studio Express 2013 中不起作用

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

在禁用 SDL 检查的情况下在发布配置中编译以下代码:

#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;
}

给出以下输出:

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 ==========

在这种情况下,为什么编译器会忽略我的#pragma。我过去曾成功地使用此方法来抑制相同的警告代码。

我从 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.

因此您可能需要将 pragma 放在 main 开始之前,或者可能在 lambda 起作用之前,但我不确定。