#ifdef _MSC_VER #pragma pack(2) #endif // (C) Copyright John Maddock 2000. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifdef TEST_STD # include # include // max_align and long_long_type #else # include # include # include #endif #include "test.hpp" #include "check_integral_constant.hpp" template union must_be_pod { int i; T t; }; template inline void no_unused_warning(const volatile T&) { } template void do_check(const T&) { typedef typename tt::aligned_storage::type t1; #if defined(BOOST_GCC) && (BOOST_GCC < 40800) // In order to test this with warnings-as-errors with GCC, we need // a slightly different initializer here to suppress spurious // GCC warnings (ie to work around a GCC buglet). t1 as1 = {{{ 0, }}}; #else t1 as1 = { 0, }; #endif must_be_pod pod1; no_unused_warning(as1); no_unused_warning(pod1); BOOST_TEST_MESSAGE(typeid(t1).name()); BOOST_CHECK(::tt::alignment_of::value == T::value); BOOST_CHECK(sizeof(t1) == T::value); #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION BOOST_CHECK(::tt::is_pod::value == true); #endif typedef typename tt::aligned_storage::type t2; #if defined(BOOST_GCC) && (BOOST_GCC < 40800) t2 as2 = {{{ 0, }}}; #else t2 as2 = { 0, }; #endif must_be_pod pod2; no_unused_warning(as2); no_unused_warning(pod2); BOOST_TEST_MESSAGE(typeid(t2).name()); BOOST_CHECK(::tt::alignment_of::value == T::value); BOOST_CHECK(sizeof(t2) == T::value*2); #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION BOOST_CHECK(::tt::is_pod::value == true); #endif #ifndef TEST_STD // Non-Tr1 behaviour: typedef typename tt::aligned_storage::type t3; #if defined(BOOST_GCC) && (BOOST_GCC < 40800) t3 as3 = {{{ 0, }}}; #else t3 as3 = { 0, }; #endif must_be_pod pod3; no_unused_warning(as3); no_unused_warning(pod3); BOOST_TEST_MESSAGE(typeid(t3).name()); BOOST_CHECK(::tt::alignment_of::value == ::tt::alignment_of< ::boost::detail::max_align>::value); BOOST_CHECK((sizeof(t3) % T::value) == 0); #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION BOOST_CHECK(::tt::is_pod::value == true); #endif #endif } TT_TEST_BEGIN(type_with_alignment) do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); #ifdef BOOST_HAS_LONG_LONG do_check(tt::integral_constant::value>()); #endif #ifdef BOOST_HAS_MS_INT64 do_check(tt::integral_constant::value>()); #endif do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); do_check(tt::integral_constant::value>()); TT_TEST_END