Merge hash, opt-in to breaking change rather than opt-out.

[SVN r64031]
This commit is contained in:
Daniel James
2010-07-15 01:12:23 +00:00
parent 6f13510580
commit 76e621bddd
3 changed files with 15 additions and 6 deletions

View File

@@ -108,10 +108,15 @@
[h2 Boost 1.44.0] [h2 Boost 1.44.0]
* Prevent implicit conversions when calling `hash_value`. If you find * Add option to prevent implicit conversions when calling `hash_value` by
that the new version breaks your code, you can enable the old defining `BOOST_HASH_NO_IMPLICIT_CASTS`. When using `boost::hash`
behaviour by defining `BOOST_HASH_ALLOW_IMPLICIT_CASTS` - although for a type that does not have `hash_value` declared but does have
I would recommend that you update your code to work with the new an implicit conversion to a type that does, it would use that
version. implicit conversion to hash it. Which can sometimes go very wrong,
e.g. using a conversion to bool and only hashing to 2 possible
values. Since fixing this is a breaking change and was only
approached quite late in the release cycle with little discussion
it's opt-in for now. This, or something like it, will become the
default in a future version.
[endsect] [endsect]

View File

@@ -7,6 +7,7 @@ import testing ;
project hash-tests project hash-tests
: requirements : requirements
<define>BOOST_HASH_NO_IMPLICIT_CASTS
<warnings>all <warnings>all
<toolset>intel:<warnings>on <toolset>intel:<warnings>on
<toolset>intel:<cxxflags>-strict-ansi <toolset>intel:<cxxflags>-strict-ansi

View File

@@ -15,7 +15,10 @@
#include <boost/functional/hash/detail/hash_float.hpp> #include <boost/functional/hash/detail/hash_float.hpp>
#include <string> #include <string>
#include <boost/limits.hpp> #include <boost/limits.hpp>
#if defined(BOOST_HASH_NO_IMPLICIT_CASTS)
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#endif
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
#include <boost/type_traits/is_pointer.hpp> #include <boost/type_traits/is_pointer.hpp>
@@ -30,7 +33,7 @@
namespace boost namespace boost
{ {
#if !defined(BOOST_HASH_ALLOW_IMPLICIT_CASTS) #if defined(BOOST_HASH_NO_IMPLICIT_CASTS)
// If you get a static assertion here, it's because hash_value // If you get a static assertion here, it's because hash_value
// isn't declared for your type. // isn't declared for your type.