Extract static_asserts out of OSL_DEBUG_LEVEL > 0

Change-Id: I604b41a5063728833d57e2589e6d3ec39eb67166
This commit is contained in:
Stephan Bergmann 2016-03-08 21:31:31 +01:00
parent 4f56db98af
commit ea5bc30fbb

View File

@ -26,17 +26,8 @@
#include <sal/types.h>
#include <uno/any2.h>
#if OSL_DEBUG_LEVEL > 0
namespace {
#if defined( SAL_W32)
#pragma pack(push, 8)
#endif
// Why hardcode like this instead of using the (generated)
// <sal/typesizes.h> ?
#if (defined(INTEL) \
&& (defined(__GNUC__) && (defined(LINUX) || defined(FREEBSD) || \
defined(NETBSD) || defined(OPENBSD) || \
@ -46,15 +37,11 @@ namespace {
#define MAX_ALIGNMENT_4
#endif
#define OFFSET_OF( s, m ) reinterpret_cast< size_t >(reinterpret_cast<char *>(&reinterpret_cast<s *>(16)->m) -16)
namespace {
#define BINTEST_VERIFYOFFSET( s, m, n ) \
if (OFFSET_OF(s, m) != static_cast<size_t>(n)) \
{ \
fprintf(stderr, "### OFFSET_OF(" #s ", " #m ") = %" SAL_PRI_SIZET "u instead of expected %" SAL_PRI_SIZET "u!!!\n", \
OFFSET_OF(s, m), static_cast<size_t>(n)); \
abort(); \
}
#if defined( SAL_W32)
#pragma pack(push, 8)
#endif
struct C1
{
@ -166,14 +153,10 @@ enum Enum
v = SAL_MAX_ENUM
};
#ifdef SAL_W32
# pragma pack(pop)
#endif
class BinaryCompatible_Impl
{
public:
BinaryCompatible_Impl();
};
BinaryCompatible_Impl::BinaryCompatible_Impl()
{
static_assert( static_cast<sal_Bool>(true) == sal_True,
"must be binary compatible" );
static_assert( static_cast<sal_Bool>(false) == sal_False,
@ -204,7 +187,7 @@ BinaryCompatible_Impl::BinaryCompatible_Impl()
static_assert(sizeof(M) == 8, "sizeof(M) != 8");
static_assert(offsetof(M, o) == 4, "offsetof(M, o) != 4");
static_assert(sizeof(N) == 12, "sizeof(N) != 12");
BINTEST_VERIFYOFFSET(N, p, 8);
static_assert(sizeof(N2) == 12, "sizeof(N2) != 12");
static_assert(offsetof(N2, p) == 8, "offsetof(N2, p) != 8");
@ -220,44 +203,24 @@ BinaryCompatible_Impl::BinaryCompatible_Impl()
static_assert(sizeof(C1) == 2, "sizeof(C1) != 2");
static_assert(sizeof(C2) == 8, "sizeof(C2) != 8");
BINTEST_VERIFYOFFSET(C2, n2, 4);
#ifdef MAX_ALIGNMENT_4
static_assert(sizeof(C3) == 20, "sizeof(C3) != 20");
BINTEST_VERIFYOFFSET(C3, d3, 8);
BINTEST_VERIFYOFFSET(C3, n3, 16);
static_assert(sizeof(C4) == 32, "sizeof(C4) != 32");
BINTEST_VERIFYOFFSET(C4, n4, 20);
BINTEST_VERIFYOFFSET(C4, d4, 24);
static_assert(sizeof(C5) == 44, "sizeof(C5) != 44");
BINTEST_VERIFYOFFSET(C5, n5, 32);
BINTEST_VERIFYOFFSET(C5, b5, 40);
static_assert(sizeof(C6) == 52, "sizeof(C6) != 52");
BINTEST_VERIFYOFFSET(C6, c6, 4);
BINTEST_VERIFYOFFSET(C6, b6, 48);
static_assert(sizeof(O2) == 24, "sizeof(O2) != 24");
BINTEST_VERIFYOFFSET(O2, p2, 20);
#else
static_assert(sizeof(C3) == 24, "sizeof(C3) != 24");
BINTEST_VERIFYOFFSET(C3, d3, 8);
BINTEST_VERIFYOFFSET(C3, n3, 16);
static_assert(sizeof(C4) == 40, "sizeof(C4) != 40");
BINTEST_VERIFYOFFSET(C4, n4, 24);
BINTEST_VERIFYOFFSET(C4, d4, 32);
static_assert(sizeof(C5) == 56, "sizeof(C5) != 56");
BINTEST_VERIFYOFFSET(C5, n5, 40);
BINTEST_VERIFYOFFSET(C5, b5, 48);
static_assert(sizeof(C6) == 72, "sizeof(C6) != 72");
BINTEST_VERIFYOFFSET(C6, c6, 8);
BINTEST_VERIFYOFFSET(C6, b6, 64);
static_assert(sizeof(O2) == 32, "sizeof(O2) != 32");
BINTEST_VERIFYOFFSET(O2, p2, 24);
#endif
static_assert(sizeof(Char3) == 3, "sizeof(Char3) != 3");
BINTEST_VERIFYOFFSET( Char4, c, 3 );
#ifdef MAX_ALIGNMENT_4
// max alignment is 4
@ -267,16 +230,61 @@ BinaryCompatible_Impl::BinaryCompatible_Impl()
static_assert(sizeof(P) == 24, "sizeof(P) != 24");
static_assert(sizeof(second) == sizeof(int), "sizeof(second) != sizeof(int)");
#endif
#if OSL_DEBUG_LEVEL > 0
#define OFFSET_OF( s, m ) reinterpret_cast< size_t >(reinterpret_cast<char *>(&reinterpret_cast<s *>(16)->m) -16)
#define BINTEST_VERIFYOFFSET( s, m, n ) \
if (OFFSET_OF(s, m) != static_cast<size_t>(n)) \
{ \
fprintf(stderr, "### OFFSET_OF(" #s ", " #m ") = %" SAL_PRI_SIZET "u instead of expected %" SAL_PRI_SIZET "u!!!\n", \
OFFSET_OF(s, m), static_cast<size_t>(n)); \
abort(); \
}
#ifdef SAL_W32
# pragma pack(pop)
class BinaryCompatible_Impl
{
public:
BinaryCompatible_Impl();
};
BinaryCompatible_Impl::BinaryCompatible_Impl()
{
BINTEST_VERIFYOFFSET(N, p, 8);
BINTEST_VERIFYOFFSET(C2, n2, 4);
#ifdef MAX_ALIGNMENT_4
BINTEST_VERIFYOFFSET(C3, d3, 8);
BINTEST_VERIFYOFFSET(C3, n3, 16);
BINTEST_VERIFYOFFSET(C4, n4, 20);
BINTEST_VERIFYOFFSET(C4, d4, 24);
BINTEST_VERIFYOFFSET(C5, n5, 32);
BINTEST_VERIFYOFFSET(C5, b5, 40);
BINTEST_VERIFYOFFSET(C6, c6, 4);
BINTEST_VERIFYOFFSET(C6, b6, 48);
BINTEST_VERIFYOFFSET(O2, p2, 20);
#else
BINTEST_VERIFYOFFSET(C3, d3, 8);
BINTEST_VERIFYOFFSET(C3, n3, 16);
BINTEST_VERIFYOFFSET(C4, n4, 24);
BINTEST_VERIFYOFFSET(C4, d4, 32);
BINTEST_VERIFYOFFSET(C5, n5, 40);
BINTEST_VERIFYOFFSET(C5, b5, 48);
BINTEST_VERIFYOFFSET(C6, c6, 8);
BINTEST_VERIFYOFFSET(C6, b6, 64);
BINTEST_VERIFYOFFSET(O2, p2, 24);
#endif
BINTEST_VERIFYOFFSET( Char4, c, 3 );
}
static BinaryCompatible_Impl aTest;
}
#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */