1
0
forked from boostorg/move

Changes to support -Wcast-align=strict

This commit is contained in:
Ion Gaztañaga
2021-12-28 15:07:56 +01:00
parent dc9edc458c
commit 7637429b6c
7 changed files with 109 additions and 36 deletions

View File

@ -804,6 +804,7 @@ Special thanks to:
[section:release_notes_boost_1_79 Boost 1.79 Release]
* The library now compiles without warnings with GCC's -Wcast-align=strict
* Fixed bugs:
* [@https://github.com/boostorg/move/pull/46 Git Issue #46: ['"Include <algorithm> when BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE is defined"]].
* [@https://github.com/boostorg/move/issues/47 Git Issue #47: ['"MSVC C5243: 'member_function_ptr': using incomplete class can cause potential ODR violation ..."]].

View File

@ -0,0 +1,61 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2015. Distributed under 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)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_MOVE_DETAIL_ADDRESSOF_HPP
#define BOOST_MOVE_DETAIL_ADDRESSOF_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <cstddef>
namespace boost {
namespace move_detail {
#if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215
#define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
#elif defined(BOOST_GCC) && BOOST_GCC >= 70000
#define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
#elif defined(__has_builtin)
#if __has_builtin(__builtin_addressof)
#define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
#endif
#endif
#ifdef BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
template<class T>
BOOST_MOVE_FORCEINLINE T *addressof( T & v ) BOOST_NOEXCEPT
{
return __builtin_addressof(v);
}
#else //BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
template <typename T>
BOOST_MOVE_FORCEINLINE T* addressof(T& obj)
{
return static_cast<T*>(
static_cast<void*>(
const_cast<char*>(
&reinterpret_cast<const volatile char&>(obj)
)));
}
#endif //BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
} //namespace move_detail {
} //namespace boost {
#endif //#ifndef BOOST_MOVE_DETAIL_ADDRESSOF_HPP

View File

@ -0,0 +1,36 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2015. Distributed under 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)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_MOVE_DETAIL_FORCE_CAST_HPP
#define BOOST_MOVE_DETAIL_FORCE_CAST_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <cstddef>
namespace boost {
namespace move_detail {
template <typename T>
BOOST_MOVE_FORCEINLINE T force_ptr(const volatile void *p)
{
return static_cast<T>(const_cast<void*>(p));
}
} //namespace move_detail {
} //namespace boost {
#endif //#ifndef BOOST_MOVE_DETAIL_FORCE_CAST_HPP

View File

@ -21,6 +21,7 @@
#include <boost/move/detail/workaround.hpp> //forceinline
#include <boost/move/detail/meta_utils_core.hpp>
#include <cstddef> //for std::size_t
#include <boost/move/detail/addressof.hpp>
//Small meta-typetraits to support move
@ -241,36 +242,7 @@ struct is_class_or_union
//////////////////////////////////////
// addressof
//////////////////////////////////////
template<class T>
struct addr_impl_ref
{
T & v_;
BOOST_MOVE_FORCEINLINE addr_impl_ref( T & v ): v_( v ) {}
BOOST_MOVE_FORCEINLINE operator T& () const { return v_; }
private:
addr_impl_ref & operator=(const addr_impl_ref &);
};
template<class T>
struct addressof_impl
{
BOOST_MOVE_FORCEINLINE static T * f( T & v, long )
{
return reinterpret_cast<T*>(
&const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
}
BOOST_MOVE_FORCEINLINE static T * f( T * v, int )
{ return v; }
};
template<class T>
BOOST_MOVE_FORCEINLINE T * addressof( T & v )
{
return ::boost::move_detail::addressof_impl<T>::f
( ::boost::move_detail::addr_impl_ref<T>( v ), 0 );
}
//////////////////////////////////////
// has_pointer_type

View File

@ -16,6 +16,7 @@
#include <boost/move/unique_ptr.hpp>
#include <boost/move/algo/detail/merge_sort.hpp>
#include <boost/move/detail/force_ptr.hpp>
#include "order_type.hpp"
#include "random_shuffle.hpp"
@ -53,8 +54,8 @@ bool test_random_shuffled(std::size_t const element_count, std::size_t const num
boost::movelib::unique_ptr<char[]> buf(new char [sizeof(T)*(element_count-element_count/2)]);
std::size_t const split = std::size_t(std::rand()) % element_count;
boost::movelib::merge_sort(elements.get(), elements.get()+split, order_type_less(), (T*)buf.get());
boost::movelib::merge_sort(elements.get()+split, elements.get()+element_count, order_type_less(), (T*)buf.get());
boost::movelib::merge_sort(elements.get(), elements.get()+split, order_type_less(), boost::move_detail::force_ptr<T*>(buf.get()));
boost::movelib::merge_sort(elements.get()+split, elements.get()+element_count, order_type_less(), boost::move_detail::force_ptr<T*>(buf.get()));
boost::movelib::adaptive_merge(elements.get(), elements.get()+split, elements.get()+element_count, order_type_less());

View File

@ -22,6 +22,7 @@
#include <boost/move/unique_ptr.hpp>
#include <boost/move/detail/nsec_clock.hpp>
#include <boost/move/detail/force_ptr.hpp>
#include "order_type.hpp"
#include "random_shuffle.hpp"
@ -70,14 +71,14 @@ template<class T, class Compare>
void adaptive_merge_buffered(T *elements, T *mid, T *last, Compare comp, std::size_t BufLen)
{
boost::movelib::unique_ptr<char[]> mem(new char[sizeof(T)*BufLen]);
boost::movelib::adaptive_merge(elements, mid, last, comp, reinterpret_cast<T*>(mem.get()), BufLen);
boost::movelib::adaptive_merge(elements, mid, last, comp, boost::move_detail::force_ptr<T*>(mem.get()), BufLen);
}
template<class T, class Compare>
void std_like_adaptive_merge_buffered(T *elements, T *mid, T *last, Compare comp, std::size_t BufLen)
{
boost::movelib::unique_ptr<char[]> mem(new char[sizeof(T)*BufLen]);
boost::movelib::merge_adaptive_ONlogN(elements, mid, last, comp, reinterpret_cast<T*>(mem.get()), BufLen);
boost::movelib::merge_adaptive_ONlogN(elements, mid, last, comp, boost::move_detail::force_ptr<T*>(mem.get()), BufLen);
}
enum AlgoType

View File

@ -18,6 +18,7 @@
#include <boost/config.hpp>
#include <boost/move/unique_ptr.hpp>
#include <boost/move/detail/nsec_clock.hpp>
#include <boost/move/detail/force_ptr.hpp>
#include <cstdlib>
using boost::move_detail::cpu_timer;
@ -68,21 +69,21 @@ template<class T, class Compare>
void adaptive_sort_buffered(T *elements, std::size_t element_count, Compare comp, std::size_t BufLen)
{
boost::movelib::unique_ptr<char[]> mem(new char[sizeof(T)*BufLen]);
boost::movelib::adaptive_sort(elements, elements + element_count, comp, reinterpret_cast<T*>(mem.get()), BufLen);
boost::movelib::adaptive_sort(elements, elements + element_count, comp, boost::move_detail::force_ptr<T*>(mem.get()), BufLen);
}
template<class T, class Compare>
void std_like_adaptive_stable_sort_buffered(T *elements, std::size_t element_count, Compare comp, std::size_t BufLen)
{
boost::movelib::unique_ptr<char[]> mem(new char[sizeof(T)*BufLen]);
boost::movelib::stable_sort_adaptive_ONlogN2(elements, elements + element_count, comp, reinterpret_cast<T*>(mem.get()), BufLen);
boost::movelib::stable_sort_adaptive_ONlogN2(elements, elements + element_count, comp, boost::move_detail::force_ptr<T*>(mem.get()), BufLen);
}
template<class T, class Compare>
void merge_sort_buffered(T *elements, std::size_t element_count, Compare comp)
{
boost::movelib::unique_ptr<char[]> mem(new char[sizeof(T)*((element_count+1)/2)]);
boost::movelib::merge_sort(elements, elements + element_count, comp, reinterpret_cast<T*>(mem.get()));
boost::movelib::merge_sort(elements, elements + element_count, comp, boost::move_detail::force_ptr<T*>(mem.get()));
}
enum AlgoType