From d5dc5033d24d98ab19a24686f0a67cad7645c5fb Mon Sep 17 00:00:00 2001 From: Andy Webber Date: Thu, 18 Dec 2014 17:27:59 -0500 Subject: [PATCH 1/5] Fixed strict aliasing violation. Changed C-style cast and dereference to std::memcpy. Exactly mirrors other code already in the file. --- include/boost/functional/hash/detail/hash_float.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/functional/hash/detail/hash_float.hpp b/include/boost/functional/hash/detail/hash_float.hpp index ee0ee87..eb9264f 100644 --- a/include/boost/functional/hash/detail/hash_float.hpp +++ b/include/boost/functional/hash/detail/hash_float.hpp @@ -68,7 +68,7 @@ namespace boost std::size_t seed = 0; if (length >= sizeof(std::size_t)) { - seed = *(std::size_t*) ptr; + std::memcpy(&seed, ptr, sizeof(std::size_t)); length -= sizeof(std::size_t); ptr += sizeof(std::size_t); From 28796cd2db446818a346bba8a0f077af5c463b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Krzemie=C5=84ski?= Date: Tue, 30 Sep 2014 15:33:08 +0200 Subject: [PATCH 2/5] removed unused header this decouples this library from Boost.Optional --- include/boost/functional/value_factory.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/boost/functional/value_factory.hpp b/include/boost/functional/value_factory.hpp index 6047908..ba94c2a 100644 --- a/include/boost/functional/value_factory.hpp +++ b/include/boost/functional/value_factory.hpp @@ -15,7 +15,6 @@ # include # include -# include # include # include # include From 980e1e4078ebe06bc9ab5a0a0540c948e8df6cc5 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 10 Jan 2015 12:33:17 +0000 Subject: [PATCH 3/5] Release note for hash change. --- hash/doc/changes.qbk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index aadeb97..35a2835 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -174,4 +174,9 @@ * Ongoing work on improving `hash_combine`. This changes the combine function which was previously defined in the reference documentation. +[h2 Boost 1.57.0] + +* Fixed strict aliasing violation + ([@https://github.com/boostorg/functional/pull/3 GitHub #3]). + [endsect] From 188c8d4c5d0b6be36d6b74855a3d6a72e6c7f444 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 10 Jan 2015 13:03:07 +0000 Subject: [PATCH 4/5] Change default factory allocator to 'void'. To remove the dependency on Boost.Optional. Supplied a macro for backwards compatibility, but that will be removed in a future release. --- factory/doc/factory.qbk | 15 +++++++++++- factory/test/Jamfile | 4 ++++ factory/test/factory_with_none_t.cpp | 36 ++++++++++++++++++++++++++++ include/boost/functional/factory.hpp | 20 ++++++++++++++-- 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 factory/test/factory_with_none_t.cpp diff --git a/factory/doc/factory.qbk b/factory/doc/factory.qbk index 7aa3faf..3b4e99b 100644 --- a/factory/doc/factory.qbk +++ b/factory/doc/factory.qbk @@ -317,7 +317,7 @@ separately allocated reference counter). }; template< typename Pointer, - class Allocator = boost::none_t, + class Allocator = void, factory_alloc_propagation AllocProp = factory_alloc_for_pointee_and_deleter > class factory; @@ -351,6 +351,19 @@ maximum arity. It defaults to 10. [endsect] +[section Changes] + +[heading Boost 1.58.0] + +In order to remove the dependency on Boost.Optional, the default parameter +for allocators has been changed from `boost::none_t` to `void`. +If you have code that has stopped working because it uses `boost::none_t`, +a quick fix is to define `BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T`, which will +restore support, but this will be removed in a future release. +It should be be relatively easy to fix this properly. + +[endsect] + [section Acknowledgements] Eric Niebler requested a function to invoke a type's constructor (with the diff --git a/factory/test/Jamfile b/factory/test/Jamfile index 6c4f6eb..fe5041f 100644 --- a/factory/test/Jamfile +++ b/factory/test/Jamfile @@ -14,5 +14,9 @@ test-suite functional/factory [ run value_factory.cpp ] [ run factory.cpp ] [ run factory_with_allocator.cpp ] + [ compile-fail factory_with_none_t.cpp ] + [ run factory.cpp : : : BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory ] + [ run factory_with_allocator.cpp : : : BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory_with_allocator ] + [ run factory_with_none_t.cpp : : : BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory_with_none_t ] ; diff --git a/factory/test/factory_with_none_t.cpp b/factory/test/factory_with_none_t.cpp new file mode 100644 index 0000000..cf203f0 --- /dev/null +++ b/factory/test/factory_with_none_t.cpp @@ -0,0 +1,36 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + Use modification and distribution are subject to the Boost Software + License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +==============================================================================*/ + +#include +#include + +#include + +class sum +{ + int val_sum; + public: + sum(int a, int b) : val_sum(a + b) { } + + operator int() const { return this->val_sum; } +}; + +int main() +{ + int one = 1, two = 2; + { + sum* instance( boost::factory< sum*, boost::none_t >()(one,two) ); + BOOST_TEST(*instance == 3); + } + { + std::auto_ptr instance( + boost::factory< std::auto_ptr, boost::none_t >()(one,two) ); + BOOST_TEST(*instance == 3); + } + return boost::report_errors(); +} diff --git a/include/boost/functional/factory.hpp b/include/boost/functional/factory.hpp index 4aa4267..67fee71 100644 --- a/include/boost/functional/factory.hpp +++ b/include/boost/functional/factory.hpp @@ -15,11 +15,14 @@ # include # include -# include # include # include # include +# if defined(BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T) +# include +# endif + # ifndef BOOST_FUNCTIONAL_FACTORY_MAX_ARITY # define BOOST_FUNCTIONAL_FACTORY_MAX_ARITY 10 # elif BOOST_FUNCTIONAL_FACTORY_MAX_ARITY < 3 @@ -35,14 +38,20 @@ namespace boost factory_passes_alloc_to_smart_pointer }; +#if defined(BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T) template< typename Pointer, class Allocator = boost::none_t, factory_alloc_propagation AP = factory_alloc_for_pointee_and_deleter > class factory; +#else + template< typename Pointer, class Allocator = void, + factory_alloc_propagation AP = factory_alloc_for_pointee_and_deleter > + class factory; +#endif //----- ---- --- -- - - - - template< typename Pointer, factory_alloc_propagation AP > - class factory + class factory { public: typedef typename boost::remove_cv::type result_type; @@ -56,6 +65,13 @@ namespace boost # include BOOST_PP_ITERATE() }; +#if defined(BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T) + template< typename Pointer, factory_alloc_propagation AP > + class factory + : public factory + {}; +#endif + template< class Pointer, class Allocator, factory_alloc_propagation AP > class factory : private Allocator::template rebind< typename boost::pointee< From a47818647def035b28b4faef07bb09c9e2e5825d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 10 Jan 2015 13:10:15 +0000 Subject: [PATCH 5/5] Fix version number in release notes. --- hash/doc/changes.qbk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash/doc/changes.qbk b/hash/doc/changes.qbk index 35a2835..f7ab411 100644 --- a/hash/doc/changes.qbk +++ b/hash/doc/changes.qbk @@ -174,7 +174,7 @@ * Ongoing work on improving `hash_combine`. This changes the combine function which was previously defined in the reference documentation. -[h2 Boost 1.57.0] +[h2 Boost 1.58.0] * Fixed strict aliasing violation ([@https://github.com/boostorg/functional/pull/3 GitHub #3]).