Boost logo

Boost :

Subject: Re: [boost] [serialization] VC++ compiler warnings
From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2011-07-11 18:22:11

[Beman Dawes]
> A 1.47.0 VC++ 10.0 build of Boost produced a lot of stupid warnings
> from Serialization in the form c:\Program Files (x86)\Microsoft Visual
> Studio 10.0\VC\INCLUDE\xutility(2227) : warning C4996:
> 'std::_Copy_impl': 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'

[Robert Ramey]
> Hmmm - it would seem to me the easiest and least intrusive way to
> deal with this is tweak the bjam build script. I build an test with
> MSVC 9.0 which also has this "facility" and I don't get the errors
> so maybe the build script already has this in it. I'll look into it.

By the way - these warnings are noisy, but they're not completely pointless. They're triggered by calling STL algorithms with raw pointers as output iterators, or with user-defined iterators that aren't marked as "checked".

In VC10+, there's a targeted way to silence these warnings: #include <iterator> and pass stdext::make_checked_array_iterator(ptr, size) or stdext::make_unchecked_array_iterator(ptr). The former actually performs checking. The latter lies to the STL by saying that it performs checking when it actually doesn't, so as to silence the warnings while retaining maximum performance.

For user-defined iterators, if you want to mark them as checked (either because they actually perform checking in debug mode like STL iterators do, or because you just want to silence the warnings), explicitly or partially specialize std::_Is_checked_helper to derive from std::true_type. You can even mark iterators as "conditionally checked", see reverse_iterator.

VC8-9 had a much more confusing story here - as I recall, they lacked stdext::make_unchecked_array_iterator() completely, and the machinery for marking user-defined iterators as checked was utterly incomprehensible as well as totally undocumented.

Stephan T. Lavavej
Visual C++ Libraries Developer

Boost list run by bdawes at, gregod at, cpdaniel at, john at