2022-08-13 01:26:00 +00:00
|
|
|
// C++98 static assert
|
|
|
|
|
2024-10-12 22:58:00 +00:00
|
|
|
#ifdef __MWERKS__
|
2022-08-13 01:26:00 +00:00
|
|
|
struct false_type {
|
2022-09-13 04:26:54 +00:00
|
|
|
static const int value = 0;
|
2022-08-13 01:26:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct true_type {
|
2022-09-13 04:26:54 +00:00
|
|
|
static const int value = 1;
|
2022-08-13 01:26:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template < int A, int B >
|
|
|
|
struct _n_is_equal : false_type {};
|
|
|
|
|
|
|
|
template < int A >
|
|
|
|
struct _n_is_equal< A, A > : true_type {};
|
|
|
|
|
|
|
|
template < class T, int N >
|
|
|
|
struct check_sizeof : _n_is_equal< sizeof(T), N > {};
|
|
|
|
|
2022-09-18 17:51:07 +00:00
|
|
|
#ifndef offsetof
|
|
|
|
typedef unsigned long size_t;
|
|
|
|
#define offsetof(type, member) ((size_t) & (((type*)0)->member))
|
|
|
|
#endif
|
2022-09-18 06:05:46 +00:00
|
|
|
#define CHECK_SIZEOF(cls, size) extern int cls##_check[check_sizeof< cls, size >::value];
|
2022-10-11 22:11:22 +00:00
|
|
|
#define NESTED_CHECK_SIZEOF(parent, cls, size) extern int cls##_check[check_sizeof< parent::cls, size >::value];
|
2022-09-18 17:51:07 +00:00
|
|
|
#define CHECK_OFFSETOF(cls, member, offset) \
|
|
|
|
extern int cls##_check_offset##[_n_is_equal< offsetof(cls, member), offset >::value];
|
2024-10-12 22:58:00 +00:00
|
|
|
#elif defined(__clang__) && defined(__powerpc__) // Enable for clangd
|
2024-10-17 05:02:14 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wc11-extensions" // Allow _Static_assert
|
2024-10-12 22:58:00 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wc++17-extensions" // Allow _Static_assert without message
|
|
|
|
#define CHECK_SIZEOF(cls, size) _Static_assert(sizeof(cls) == size);
|
|
|
|
#define NESTED_CHECK_SIZEOF(parent, cls, size) _Static_assert(sizeof(parent::cls) == size);
|
|
|
|
#define CHECK_OFFSETOF(cls, member, offset) _Static_assert(offsetof(cls, member) == offset);
|
2022-08-13 01:26:00 +00:00
|
|
|
#else
|
|
|
|
#define CHECK_SIZEOF(cls, size)
|
2022-10-11 22:11:22 +00:00
|
|
|
#define NESTED_CHECK_SIZEOF(parent, cls, size)
|
2022-09-19 04:19:46 +00:00
|
|
|
#define CHECK_OFFSETOF(cls, member, offset)
|
2022-09-18 06:05:46 +00:00
|
|
|
#endif
|