5

Visual Studio 2015 Community Edition gives the following error when compiling in debug, but not when compiling in release:

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. 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. I've tried the following solutions that were suggested in the documentation, on StackOverflow, or elsewhere:

  • Add 4996 to the "Disable Specific Warnings" field in Project Settings > Configuration Properties > C/C++ > Advanced.
  • Add /wd4996 to the "Command Arguments" field in Project Settings > Configuration Properties > Debugging.
  • Add #pragma warning (disable : 4996) at the top of the offending file, and/or above the offending function.
  • 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.
  • Add the definitions from the previous solution with a #define directive to the top of the offending file.
  • Add the definitions from the previous solution but prefixed with /D or with -D to the "Command Arguments" field.

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?

AJM
  • 1,317
  • 2
  • 15
  • 30
FWDekker
  • 1,823
  • 2
  • 20
  • 26
  • Wait, did you try to `#define -D_SCL_SECURE_NO_WARNINGS`? – Rakete1111 Jun 27 '16 at 18:09
  • Is it possible that the whitespace after `#pragma warning` is being problematic? Did you clean the project? Sorry, just throwing ideas out there in case it sticks :/ – meepzh Jun 27 '16 at 18:11
  • @Rakete1111 If I try that it tells me that it "expected an identifier" at the `-`. Without the `-` it still gives the error. – FWDekker Jun 27 '16 at 18:15
  • @meepzh I've tried it with and without spaces after `warning` and around the colon, but it doesn't fix it. Cleaning the solution and the project, and rebuilding doesn't fix it either. – FWDekker Jun 27 '16 at 18:18
  • The msdn documentation page you linked to has a special note (and example) about _ITERATOR_DEBUG_LEVEL and [Checked Iterators](https://msdn.microsoft.com/en-us/library/aa985965.aspx). – dxiv Jun 27 '16 at 22:16
  • This still seems to be an problem in VS2017; updating the Configuration Properties didn't work for me, but the `#pragma warning` did work. – Sean Werkema Mar 27 '17 at 03:05

4 Answers4

5

define NO_WARN_MBCS_MFC_DEPRECATION

Community
  • 1
  • 1
1

Disabling warning 4996 has no effect on std::copy warnings. To suppress this warning place the following at the top of your source file:

#define _SECURE_SCL_DEPRECATE 0
#include <algorithm>
Robin Rowe
  • 11
  • 1
1

Add _CRT_NONSTDC_NO_WARNINGS to preprocessor definitions.

Jiminion
  • 5,080
  • 1
  • 31
  • 54
0

In your stdafx.h:

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

Worked for me VS2015 update 3