Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 343
chili Avatar asked Mar 28 '16 12:03

chili


People also ask

How do I turn off pragma warning?

Syntax for #pragma If we want to do disable the warnings then we use this syntax: #pragma warning disable <warning code/warning name>

How do I ignore warnings in C#?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.

How do I enable warnings in Visual Studio?

If you want to turn it on (or off) in the project setting, you have to go to: Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter: /w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.


1 Answers

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.

like image 165
Christopher Oicles Avatar answered Oct 07 '22 06:10

Christopher Oicles