From 02506df225e9f827722a268f7734543132ef5bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 18 May 2013 09:41:39 +0000 Subject: [PATCH] static assert when complex pointer to member pointer must be used in MSVC in parent_from_member. [SVN r84338] --- .../intrusive/detail/parent_from_member.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/boost/intrusive/detail/parent_from_member.hpp b/include/boost/intrusive/detail/parent_from_member.hpp index 2afffb4..f86a0e7 100644 --- a/include/boost/intrusive/detail/parent_from_member.hpp +++ b/include/boost/intrusive/detail/parent_from_member.hpp @@ -16,9 +16,9 @@ #include #if defined(BOOST_MSVC) || ((defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && defined(BOOST_INTEL)) - -#define BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER -#include + #define BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER + #include + #include #endif namespace boost { @@ -29,7 +29,7 @@ template inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member) { //The implementation of a pointer to member is compiler dependent. - #if defined(BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER) + #if defined(BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER) //msvc compliant compilers use their the first 32 bits as offset (even in 64 bit mode) union caster_union { @@ -37,6 +37,10 @@ inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_t boost::int32_t offset; } caster; caster.ptr_to_member = ptr_to_member; + //MSVC ABI can use up to 3 int32 to represent pointer to member data + //with virtual base classes, in those cases there is no simple to + //obtain the address of parent. So static assert to avoid runtime errors + BOOST_STATIC_ASSERT( sizeof(caster) == sizeof(boost::int32_t) ); return std::ptrdiff_t(caster.offset); //This works with gcc, msvc, ac++, ibmcpp #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \ @@ -84,8 +88,8 @@ inline const Parent *parent_from_member(const Member *member, const Member Paren } //namespace intrusive { } //namespace boost { -#ifdef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER -#undef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER +#ifdef BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER +#undef BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER #endif #include