From 76e621bddd113b0e14c155d10d878ff90b836efa Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 15 Jul 2010 01:12:23 +0000 Subject: [PATCH] Merge hash, opt-in to breaking change rather than opt-out. [SVN r64031] --- hash/doc/changes.qbk | 15 ++++++++++----- hash/test/Jamfile.v2 | 1 + include/boost/functional/hash/hash.hpp | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index bc6f4ca..eec4876 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -108,10 +108,15 @@ [h2 Boost 1.44.0] -* Prevent implicit conversions when calling `hash_value`. If you find - that the new version breaks your code, you can enable the old - behaviour by defining `BOOST_HASH_ALLOW_IMPLICIT_CASTS` - although - I would recommend that you update your code to work with the new - version. +* Add option to prevent implicit conversions when calling `hash_value` by + defining `BOOST_HASH_NO_IMPLICIT_CASTS`. When using `boost::hash` + for a type that does not have `hash_value` declared but does have + an implicit conversion to a type that does, it would use that + 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] diff --git a/hash/test/Jamfile.v2 b/hash/test/Jamfile.v2 index c2d8084..1b35eed 100644 --- a/hash/test/Jamfile.v2 +++ b/hash/test/Jamfile.v2 @@ -7,6 +7,7 @@ import testing ; project hash-tests : requirements + BOOST_HASH_NO_IMPLICIT_CASTS all intel:on intel:-strict-ansi diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index 54407d6..108d3ed 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -15,7 +15,10 @@ #include #include #include + +#if defined(BOOST_HASH_NO_IMPLICIT_CASTS) #include +#endif #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #include @@ -30,7 +33,7 @@ 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 // isn't declared for your type.