37

I'm getting the following warning

warning C4996: 'std::_Uninitialized_copy0': Function call 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' c:\program files\microsoft visual studio 10.0\vc\include\memory 348

I can't seem to find any information that would help to combat this warning. By looking at the output it seems this warning has something to do with Boost.Signals2 and auto_buffer.

Is this safe to ignore or can I remove it somehow?

Anthony
  • 12,177
  • 9
  • 69
  • 105
  • Sorry, by remove I meant make a code change (as apposed to the compiler switch recommended by MS.) – Anthony Jul 23 '10 at 11:06
  • I would like to see exactly that line: c:\program files\microsoft visual studio 10.0\vc\include\memory 348 – atamanroman Jul 23 '10 at 11:13
  • possible duplicate of [Compiler Error: Function call with parameters that may be unsafe](http://stackoverflow.com/questions/903064/compiler-error-function-call-with-parameters-that-may-be-unsafe) – jpalecek Jul 23 '10 at 11:18
  • Sure, I read the other question. I'm a little concerned about boost throwing these warnings. Is it still safe to ignore? – Anthony Jul 23 '10 at 11:26
  • As the message says, the call relies on its caller to check the passed values. It's safe to assume that boost knows what they were doing. – Gunslinger47 Jul 23 '10 at 11:32
  • 1
    +1 glad to see the exact question I wanted to ask since I started using boost::signals2. ;-). – Stephane Rolland Nov 07 '12 at 13:32
  • possible duplicate of [C++ Boost: what's the cause of this warning?](http://stackoverflow.com/questions/1301277/c-boost-whats-the-cause-of-this-warning) – sgryzko Sep 25 '14 at 16:57

2 Answers2

59

First, I would like to say that I am quite fond of compiler warnings. I invoke gcc with -Wall -Wextra.

However, the MSVC warning C4996 mostly fires on completely valid code. The changes proposed in the warning text often seriously compromise the code portability, while they never substantially improve the code quality. Thus I regularly suppress this warning in my MSVC projects (Project properties->C++->Advanced->Disable specific warnings).

Check also this and that discussions.

Community
  • 1
  • 1
ssegvic
  • 3,123
  • 1
  • 20
  • 21
  • 1
    A lot of these warnings are about old C functions using char* (strcpy, strcat, sprintf).. Isn't recommended to replace these with STL stream methods ? Since then these warnings are welcome (but unfortunately these warning doesn't recommend stream functions but rather to use specific windows functions like strcpy_s).. – kingsjester Sep 26 '22 at 15:12
  • 1
    I agree that streams are most often a preferred alternative for new code. Still, classic C-style functions may be faster due to less re-allocations. In any case, as you say, the recommended resolution is unfortunate. – ssegvic Sep 30 '22 at 07:40
0

This error is generated because the code the compiler produces is not thread-safe. This means that if you are using multi-threaded coding, some of your stream I/O can (and probably will) get lost because the internal I/O buffers are shared. The suggested substitute functions will "eliminate" this problem.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
DocDJ
  • 31
  • 5