简体   繁体   English

Visual Studio 2015不会禁止错误C4996

[英]Visual Studio 2015 won't suppress error C4996

Visual Studio 2015 Community Edition gives the following error when compiling in debug, but not when compiling in release: 在调试中编译时,Visual Studio 2015 Community Edition会出现以下错误,但在发布时进行编译时则不会:

std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

I was able to trace back the source of this error to lines 214 and 242 of this third party library I'm using to write bitmap images. 我能够将此错误的来源追溯到我用于编写位图图像的第三方库的第214和242行。 I don't fully understand what is going on in these parts, so I'd rather not mess with it. 我不完全了解这些部分发生了什么,所以我宁愿不要搞乱它。


I'm trying to disable this error, but Visual Studio won't let me. 我正在尝试禁用此错误,但Visual Studio不会让我。 I've tried the following solutions that were suggested in the documentation , on StackOverflow, or elsewhere: 我已经尝试了文档 ,StackOverflow或其他地方建议的以下解决方案:

  • Add 4996 to the "Disable Specific Warnings" field in Project Settings > Configuration Properties > C/C++ > Advanced. 4996添加到项目设置>配置属性> C / C ++>高级中的“禁用特定警告”字段。
  • Add /wd4996 to the "Command Arguments" field in Project Settings > Configuration Properties > Debugging. /wd4996添加到项目设置>配置属性>调试中的“命令参数”字段。
  • Add #pragma warning (disable : 4996) at the top of the offending file, and/or above the offending function. 在违规文件的顶部和/或违规功能上方添加#pragma warning (disable : 4996)
  • Add _SCL_SECURE_NO_WARNINGS , _SCL_NONSTDC_NO_WARNINGS , _SCL_OBSOLETE_NO_WARNINGS , _SCL_SECURE_NO_WARNINGS_GLOBAL , and combinations thereof to the "Preprocessor Definitions" field in Project Settings > Configuration Properties > C/C++ > Preprocessor. _SCL_SECURE_NO_WARNINGS_SCL_NONSTDC_NO_WARNINGS_SCL_OBSOLETE_NO_WARNINGS_SCL_SECURE_NO_WARNINGS_GLOBAL及其组合添加到项目设置>配置属性> C / C ++>预处理器中的“预处理器定义”字段。
  • Add the definitions from the previous solution with a #define directive to the top of the offending file. 使用#define指令将以前解决方案中的定义添加到违规文件的顶部。
  • Add the definitions from the previous solution but prefixed with /D or with -D to the "Command Arguments" field. 添加上一个解决方案中的定义,但以/D-D为前缀到“Command Arguments”字段。

But none of this fixes the issue for me. 但这一切都没有为我解决问题。


What could possibly be the reason for Visual Studio to keep insisting on displaying this error? 可能是Visual Studio始终坚持显示此错误的原因是什么?

定义NO_WARN_MBCS_MFC_DEPRECATION

Disabling warning 4996 has no effect on std::copy warnings. 禁用警告4996对std :: copy警告没有影响。 To suppress this warning place the following at the top of your source file: 要禁止显示此警告,请将以下内容放在源文件的顶部:

#define _SECURE_SCL_DEPRECATE 0
#include <algorithm>

将_CRT_NONSTDC_NO_WARNINGS添加到预处理器定义。

In your stdafx.h: 在你的stdafx.h中:

#pragma warning( push )
#pragma warning( disable: 4996)
#include <algorithm>
#pragma warning( pop )

Worked for me VS2015 update 3 为我工作VS2015更新3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM