more extensive speculative fix

This commit is contained in:
Andrzej Krzemienski
2016-02-20 16:36:48 +01:00
parent c0084a0451
commit 9118518516
2 changed files with 12 additions and 9 deletions

View File

@@ -49,21 +49,24 @@ class aligned_storage
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
// 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() };
return *caster.as_ptype;
return caster.as_ptype;
}
T & ref()
T * ptr_ref()
{
union { void* ap_pvoid; T* as_ptype; } caster = { address() };
return *caster.as_ptype;
return caster.as_ptype;
}
#else
T const& ref() const { return *static_cast<T const*>(address()); }
T & ref() { return *static_cast<T *> (address()); }
T const* ptr_ref() const { return static_cast<T const*>(address()); }
T * ptr_ref() { return static_cast<T *> (address()); }
#endif
T const& ref() const { return *ptr_ref(); }
T & ref() { return *ptr_ref(); }
} ;
} // namespace optional_detail