diff --git a/include/boost/type_traits/alignment_of.hpp b/include/boost/type_traits/alignment_of.hpp index e8e4834..45cf38f 100644 --- a/include/boost/type_traits/alignment_of.hpp +++ b/include/boost/type_traits/alignment_of.hpp @@ -30,6 +30,10 @@ template struct alignment_of; // get the alignment of some arbitrary type: namespace detail { +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4324) // structure was padded due to __declspec(align()) +#endif template struct alignment_of_hack { @@ -37,7 +41,9 @@ struct alignment_of_hack T t; alignment_of_hack(); }; - +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif template struct alignment_logic diff --git a/include/boost/type_traits/type_with_alignment.hpp b/include/boost/type_traits/type_with_alignment.hpp index 49816d2..26a671a 100644 --- a/include/boost/type_traits/type_with_alignment.hpp +++ b/include/boost/type_traits/type_with_alignment.hpp @@ -232,6 +232,29 @@ BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a16,true) BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a32,true) } #endif +#if defined(BOOST_MSVC) || (defined(BOOST_INTEL) && defined(_MSC_VER)) +namespace align { +struct __declspec(align(8)) a8 { char m[8]; }; +struct __declspec(align(16)) a16 { char m[16]; }; +struct __declspec(align(32)) a32 { char m[32]; }; +struct __declspec(align(64)) a64 { char m[64]; }; +struct __declspec(align(128)) a128 { char m[128]; }; +} + +template<> class type_with_alignment<8> { public: typedef align::a8 type; }; +template<> class type_with_alignment<16> { public: typedef align::a16 type; }; +template<> class type_with_alignment<32> { public: typedef align::a32 type; }; +template<> class type_with_alignment<64> { public: typedef align::a64 type; }; +template<> class type_with_alignment<128> { public: typedef align::a128 type; }; + +namespace detail { +BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a8,true) +BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a16,true) +BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a32,true) +BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a64,true) +BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,::boost::align::a128,true) +} +#endif #else diff --git a/test/type_with_alignment_test.cpp b/test/type_with_alignment_test.cpp index 3e1f610..77f399c 100644 --- a/test/type_with_alignment_test.cpp +++ b/test/type_with_alignment_test.cpp @@ -14,6 +14,17 @@ # include #endif +#if defined(BOOST_MSVC) || (defined(BOOST_INTEL) && defined(_MSC_VER)) +#if _MSC_VER >= 1400 +#include +#endif +struct __declspec(align(8)) a8 { char m[8]; }; +struct __declspec(align(16)) a16 { char m[16]; }; +struct __declspec(align(32)) a32 { char m[32]; }; +struct __declspec(align(64)) a64 { char m[64]; }; +struct __declspec(align(128)) a128 { char m[128]; }; +#endif + TT_TEST_BEGIN(type_with_alignment) BOOST_MESSAGE(typeid(::tt::type_with_alignment< @@ -69,6 +80,40 @@ BOOST_CHECK(::tt::alignment_of< >::type >::value == ::boost::alignment_of<__int64>::value); #endif +#if defined(BOOST_MSVC) || (defined(BOOST_INTEL) && defined(_MSC_VER)) +#if _MSC_VER >= 1400 +BOOST_CHECK(::tt::alignment_of< + ::tt::type_with_alignment< + ::tt::alignment_of<__m128>::value + >::type + >::value == ::boost::alignment_of<__m128>::value); +BOOST_CHECK(::tt::alignment_of< + ::tt::type_with_alignment< + ::tt::alignment_of<__m64>::value + >::type + >::value == ::boost::alignment_of<__m64>::value); +#endif +BOOST_CHECK(::tt::alignment_of< + ::tt::type_with_alignment< + ::tt::alignment_of::value + >::type + >::value == ::boost::alignment_of::value); +BOOST_CHECK(::tt::alignment_of< + ::tt::type_with_alignment< + ::tt::alignment_of::value + >::type + >::value == ::boost::alignment_of::value); +BOOST_CHECK(::tt::alignment_of< + ::tt::type_with_alignment< + ::tt::alignment_of::value + >::type + >::value == ::boost::alignment_of::value); +BOOST_CHECK(::tt::alignment_of< + ::tt::type_with_alignment< + ::tt::alignment_of::value + >::type + >::value == ::boost::alignment_of::value); +#endif BOOST_CHECK(::tt::alignment_of< ::tt::type_with_alignment< ::tt::alignment_of::value