mirror of
https://github.com/boostorg/optional.git
synced 2025-07-30 20:47:18 +02:00
more extensive speculative fix
This commit is contained in:
@ -49,21 +49,24 @@ class aligned_storage
|
|||||||
|
|
||||||
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
|
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
|
||||||
// This workaround is supposed to silence GCC warnings about broken strict aliasing rules
|
// This workaround is supposed to silence GCC warnings about broken strict aliasing rules
|
||||||
T const& ref() const
|
T const* ptr_ref() const
|
||||||
{
|
{
|
||||||
union { void const* ap_pvoid; T const* as_ptype; } caster = { address() };
|
union { void const* ap_pvoid; T const* as_ptype; } caster = { address() };
|
||||||
return *caster.as_ptype;
|
return caster.as_ptype;
|
||||||
}
|
}
|
||||||
T & ref()
|
T * ptr_ref()
|
||||||
{
|
{
|
||||||
union { void* ap_pvoid; T* as_ptype; } caster = { address() };
|
union { void* ap_pvoid; T* as_ptype; } caster = { address() };
|
||||||
return *caster.as_ptype;
|
return caster.as_ptype;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
T const& ref() const { return *static_cast<T const*>(address()); }
|
T const* ptr_ref() const { return static_cast<T const*>(address()); }
|
||||||
T & ref() { return *static_cast<T *> (address()); }
|
T * ptr_ref() { return static_cast<T *> (address()); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
T const& ref() const { return *ptr_ref(); }
|
||||||
|
T & ref() { return *ptr_ref(); }
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
} // namespace optional_detail
|
} // namespace optional_detail
|
||||||
|
@ -555,13 +555,13 @@ class optional_base : public optional_tag
|
|||||||
reference_const_type get_impl() const { return m_storage.ref() ; }
|
reference_const_type get_impl() const { return m_storage.ref() ; }
|
||||||
reference_type get_impl() { return m_storage.ref() ; }
|
reference_type get_impl() { return m_storage.ref() ; }
|
||||||
|
|
||||||
pointer_const_type get_ptr_impl() const { return boost::addressof(m_storage.ref()); }
|
pointer_const_type get_ptr_impl() const { return m_storage.ptr_ref(); }
|
||||||
pointer_type get_ptr_impl() { return boost::addressof(m_storage.ref()); }
|
pointer_type get_ptr_impl() { return m_storage.ptr_ref(); }
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
|
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
|
||||||
void destroy_impl ( ) { boost::addressof(m_storage.ref())->~T() ; m_initialized = false ; }
|
void destroy_impl ( ) { m_storage.ptr_ref()->~T() ; m_initialized = false ; }
|
||||||
#else
|
#else
|
||||||
void destroy_impl ( ) { m_storage.ref().T::~T() ; m_initialized = false ; }
|
void destroy_impl ( ) { m_storage.ref().T::~T() ; m_initialized = false ; }
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user