Added alignof intrinsic support: new tests and docs.

Also added test case from issue #1946.

[SVN r46128]
This commit is contained in:
John Maddock committed 2008-06-04 17:09:37 +00:00
1 parent 3cc8416611
commit 21d466f451
93 files changed
+350 -218

No files matched your search

+35
View File
@@ -16,6 +16,37 @@
// VC++ emits an awful lot of warnings unless we define these:
#ifdef BOOST_MSVC
# pragma warning(disable:4244)
//
// What follows here is the test case for issue 1946.
//
#include <boost/function.hpp>
// This kind of packing is set within MSVC 9.0 headers.
// E.g. std::ostream has it.
#pragma pack(push,8)
// The issue is gone if Root has no data members
struct Root { int a; };
// The issue is gone if Root is inherited non-virtually
struct A : virtual public Root {};
#pragma pack(pop)
//
// This class has 8-byte alignment but is 44 bytes in size, which means
// that elements in an array of this type will not actually be 8 byte
// aligned. This appears to be an MSVC bug, and throws off our
// alignment calculations: causing us to report a non-sensical 12-byte
// alignment for this type. This is fixed by using the native __alignof
// operator.
//
class issue1946 :
public A
{
public:
// The issue is gone if the type is not a boost::function. The signature doesn't matter.
typedef boost::function0< void > function_type;
function_type m_function;
};
#endif
@@ -63,6 +94,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<POD_UDT>::value, ALIGNOF(POD_UD
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<empty_UDT>::value, ALIGNOF(empty_UDT));
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<union_UDT>::value, ALIGNOF(union_UDT));
#if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400)
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<issue1946>::value, ALIGNOF(issue1946));
#endif
TT_TEST_END
+8 -4
View File
@@ -35,6 +35,14 @@ void check_call(const T& v)
#define TYPE_WITH_ALIGNMENT_TEST(T)\
{\
std::cout << "\ntesting type " << typeid(T).name() << std::endl;\
std::cout << "Alignment of T is " << ::tt::alignment_of< T >::value << std::endl;\
std::cout << "Aligned type is " << typeid(::tt::type_with_alignment< ::tt::alignment_of< T >::value>::type).name() << std::endl;\
std::cout << "Alignment of aligned type is " << ::tt::alignment_of<\
::tt::type_with_alignment<\
::tt::alignment_of< T >::value\
>::type\
>::value << std::endl;\
BOOST_CHECK(::tt::alignment_of<\
::tt::type_with_alignment<\
::tt::alignment_of< T >::value\
@@ -57,10 +65,6 @@ BOOST_CHECK(::tt::is_pod<\
TT_TEST_BEGIN(type_with_alignment)
BOOST_MESSAGE(typeid(::tt::type_with_alignment<
::tt::alignment_of<char>::value
>::type).name());
TYPE_WITH_ALIGNMENT_TEST_EX(char)
TYPE_WITH_ALIGNMENT_TEST_EX(short)
TYPE_WITH_ALIGNMENT_TEST_EX(int)