Visual Studio 2013 doesn't ignore disabled warnings

后端 未结 3 525
青春惊慌失措
青春惊慌失措 2020-12-16 17:24

Good morning all. So I\'m attempting to disable Warning 4996 in our c++ projects. It seems to be included in the command line as shown below, but upon compiling, still pops

相关标签:
3条回答
  • 2020-12-16 18:11

    It looks like #pragma warning(disable: 4996) will not disable the MBCS deprecation warning due to the #pragma warning(1: 4996) before the _declspec(deprecated) line in afx.h

    For obscure reasons, you must use #define NO_WARN_MBCS_MFC_DEPRECATION to disable this instead.

    see afx.h lines 28-33

    #ifndef NO_WARN_MBCS_MFC_DEPRECATION
    #ifdef _MBCS
    // Warn about MBCS support being deprecated: see http://go.microsoft.com/fwlink/p/?LinkId=279048 for more information.
    #pragma warning(push)
    #pragma warning(1 : 4996)
    inline __declspec(deprecated("MBCS support in MFC is deprecated and may be removed in a future version of MFC.")) void MBCS_Support_Deprecated_In_MFC() { }
    
    0 讨论(0)
  • 2020-12-16 18:14

    I have had a similar issue but it was on some functions from io.h and string.h such as these:

    source.cxx(713) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details. C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(215) : see declaration of 'stricmp'

    source.cxx(2416) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(207) : see declaration of 'strdup'

    source.cxx(2249) : warning C4996: 'isatty': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _isatty. See online help for det ails.

    Due to the need to have the exact same code run be built on other platforms, I had to find a solution without fiddling much in code as this occurred all over the project in a lot of files.

    The solution was to add this compiler flag _CRT_NONSTDC_NO_DEPRECATE. This can be done in one of two ways:

    1. Passing -D_CRT_NONSTDC_NO_DEPRECATE if you are using the cl command directly
    2. Or from Visual Studio GUI if you use it for the building process. Add _CRT_NONSTDC_NO_DEPRECATE in Project Properties > C\C++ > Preprocessor > Preprocessor Definition
    0 讨论(0)
  • 2020-12-16 18:15

    In order to Pat Brenner (Visual C++ Libraries Development Team) mentioned in his blog ,

    we are deprecating MBCS support in MFC for Visual Studio 2013. This keeps MFC more closely aligned with the Windows SDK itself, because many of the newest controls and messages are Unicode only

    This warning can be eliminated by adding the NO_WARN_MBCS_MFC_DEPRECATION preprocessor definition to your project build definitions.

    Then do this.

    Go to Project Properties-> C\C++ ->Preprocessor->Preprocessor Definition and add NO_WARN_MBCS_MFC_DEPRECATION

    0 讨论(0)
提交回复
热议问题