mirror of
https://github.com/boostorg/move.git
synced 2025-08-01 21:34:27 +02:00
Add BOOST_MOVE_TO_LV to help reducing potential UB
This commit is contained in:
@@ -58,6 +58,7 @@
|
|||||||
#include <boost/move/detail/type_traits.hpp>
|
#include <boost/move/detail/type_traits.hpp>
|
||||||
|
|
||||||
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) reinterpret_cast<RV_TYPE>(ARG)
|
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) reinterpret_cast<RV_TYPE>(ARG)
|
||||||
|
#define BOOST_MOVE_TO_LV_CAST(LV_TYPE, ARG) static_cast<LV_TYPE>(ARG)
|
||||||
|
|
||||||
//Move emulation rv breaks standard aliasing rules so add workarounds for some compilers
|
//Move emulation rv breaks standard aliasing rules so add workarounds for some compilers
|
||||||
#if defined(BOOST_GCC) && (BOOST_GCC >= 40400) && (BOOST_GCC < 40500)
|
#if defined(BOOST_GCC) && (BOOST_GCC >= 40400) && (BOOST_GCC < 40500)
|
||||||
@@ -218,6 +219,10 @@
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
BOOST_MOVE_FORCEINLINE T& unrv(::boost::rv<T> &rv) BOOST_NOEXCEPT
|
||||||
|
{ return BOOST_MOVE_TO_LV_CAST(T&, rv); }
|
||||||
|
|
||||||
} //namespace move_detail {
|
} //namespace move_detail {
|
||||||
} //namespace boost {
|
} //namespace boost {
|
||||||
|
|
||||||
@@ -229,6 +234,11 @@
|
|||||||
::boost::move((BASE_TYPE&)(ARG))
|
::boost::move((BASE_TYPE&)(ARG))
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#define BOOST_MOVE_TO_LV(ARG) \
|
||||||
|
::boost::move_detail::unrv(ARG)
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// BOOST_MOVABLE_BUT_NOT_COPYABLE
|
// BOOST_MOVABLE_BUT_NOT_COPYABLE
|
||||||
@@ -480,6 +490,17 @@
|
|||||||
::boost::move((BASE_TYPE&)(ARG))
|
::boost::move((BASE_TYPE&)(ARG))
|
||||||
//
|
//
|
||||||
|
|
||||||
|
//!This macro is used to achieve portable optimal move constructors.
|
||||||
|
//!
|
||||||
|
//!In C++03 mode, when accessing a member of type through a rvalue (implemented as a `rv<T> &` type, where rv<T> derives
|
||||||
|
//!from T) triggers a potential UB as the program never creates objects of type rv<T>. This macro casts back `rv<T>` to
|
||||||
|
//!`T&` so that access to member types are done through the original type.
|
||||||
|
//!
|
||||||
|
//!In C++11 compilers the cast from a rvalue reference of a derived type to a rvalue reference of
|
||||||
|
//!a base type is implicit, so it's a no-op.
|
||||||
|
#define BOOST_MOVE_TO_LV(ARG) ARG
|
||||||
|
//
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace move_detail {
|
namespace move_detail {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user