Fix any_range with non-reference references can cause UB

This commit is contained in:
code@jendruk.com
2019-05-07 12:06:05 +02:00
parent 77a4dd5124
commit dbb6ef424f
3 changed files with 80 additions and 13 deletions
@@ -14,6 +14,7 @@
#include <boost/iterator/iterator_categories.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_copy_constructible.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
@@ -35,15 +36,18 @@ namespace boost
};
template<class T>
struct mutable_reference_type_generator
struct reference_as_value_type_generator
{
typedef typename mpl::if_<
typename mpl::and_<
typename is_const<T>::type,
typename mpl::not_<typename is_reference<T>::type>::type
typename is_copy_constructible<
typename remove_const<
typename remove_reference<T>::type
>::type
>::type,
T,
typename add_reference<T>::type
typename remove_const<
typename remove_reference<T>::type
>::type,
T
>::type type;
};
@@ -53,16 +57,12 @@ namespace boost
>
struct any_incrementable_iterator_interface
{
typedef typename mutable_reference_type_generator<
Reference
>::type reference;
typedef Reference reference;
typedef typename const_reference_type_generator<
Reference
>::type const_reference;
typedef typename remove_const<
typename remove_reference<Reference>::type
typedef typename reference_as_value_type_generator<
Reference
>::type reference_as_value_type;
typedef Buffer buffer_type;