Opened 9 years ago

Closed 9 years ago

#9503 closed Patches (wontfix)

Compile error C4996 with boost::uuids:uuid and vc2012

Reported by: Craig Hutchinson <craig@…> Owned by: Andy Tompkins
Milestone: To Be Determined Component: uuid
Version: Boost 1.55.0 Severity: Problem
Keywords: C4996 vc2012 Cc:

Description

When compiling uuid under vc2012 with safe check enabled the C4996 warning is escalated to ERROR status.

c:\program files (x86)\microsoft visual studio 11.0\vc\include\algorithm(965): error C4996: 'std::_Swap_ranges': 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'
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\algorithm(950) : see declaration of 'std::_Swap_ranges'
1>          c:\boost\boost_1_55_0\boost\uuid\uuid.hpp(151) : see reference to function template instantiation '_FwdIt2 std::swap_ranges<boost::uuids::uuid::iterator,boost::uuids::uuid::iterator>(_FwdIt1,_FwdIt1,_FwdIt2)' being compiled
1>          with
1>          [
1>              _FwdIt2=boost::uuids::uuid::iterator,
1>              _FwdIt1=boost::uuids::uuid::iterator
1>          ]

The pragma that already exists in boost_1_55_0\boost\uuid\uuid.hpp does not cater for this:

#pragma warning(disable : 4996)

I have attached a modified uuid which uses std::array as a sensible solution - this was actually commented in the original code. Now this enables safe iterators for compiler checks to be performed and removed any need for the #pragma pre-processor directives. There may be other changes needed elsewhere(i.e. &*uuid.begin() in functions needing void*).

Attachments (1)

uuid.hpp (6.9 KB ) - added by Craig Hutchinson <craig@…> 9 years ago.
Modified uuid.hpp to use std::array

Download all attachments as: .zip

Change History (4)

by Craig Hutchinson <craig@…>, 9 years ago

Attachment: uuid.hpp added

Modified uuid.hpp to use std::array

comment:1 by Craig Hutchinson <craig@…>, 9 years ago

I should add that I changed is_nil() to use find_if(). It is wrong and should return ... == end();

comment:2 by anonymous, 9 years ago

Component: Noneuuid
Owner: set to Andy Tompkins

comment:3 by Steven Watanabe, 9 years ago

Resolution: wontfix
Status: newclosed

Just use -D_SCL_SECURE_NO_WARNINGS. Using std::array will break compilation on C++03 compilers. This warning is spurious, difficult to work around, and impossible to suppress.

Note: See TracTickets for help on using tickets.