Skip to content

Commit

Permalink
Use launder to make sure compilers assume that a parent type exists a…
Browse files Browse the repository at this point in the history
…nd it's alive
  • Loading branch information
igaztanaga committed Aug 11, 2024
1 parent b9b83bd commit 008795c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/boost/intrusive/detail/parent_from_member.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/workaround.hpp>
#include <boost/move/detail/launder.hpp>
#include <cstddef>

#if defined(_MSC_VER)
Expand Down Expand Up @@ -90,15 +91,15 @@ BOOST_INTRUSIVE_FORCEINLINE std::ptrdiff_t offset_from_pointer_to_member(const M
template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
{
return reinterpret_cast<Parent*>
(reinterpret_cast<std::size_t>(member) - static_cast<std::size_t>(offset_from_pointer_to_member(ptr_to_member)));
return boost::move_detail::launder(reinterpret_cast<Parent*>
(reinterpret_cast<std::size_t>(member) - static_cast<std::size_t>(offset_from_pointer_to_member(ptr_to_member))));
}

template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
{
return reinterpret_cast<const Parent*>
( reinterpret_cast<std::size_t>(member) - static_cast<std::size_t>(offset_from_pointer_to_member(ptr_to_member)) );
return boost::move_detail::launder(reinterpret_cast<const Parent*>
( reinterpret_cast<std::size_t>(member) - static_cast<std::size_t>(offset_from_pointer_to_member(ptr_to_member)) ));
}

} //namespace detail {
Expand Down

0 comments on commit 008795c

Please sign in to comment.