compat.h: Use C++17, C++11, or C11 static_assert if available.

git-svn-id: https://svn.eduke32.com/eduke32@6472 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-10-09 07:37:14 +00:00
parent 4966b0922d
commit dfb98028f1

View file

@ -188,15 +188,22 @@
# define EDUKE32_PRETTY_FUNCTION EDUKE32_FUNCTION # define EDUKE32_PRETTY_FUNCTION EDUKE32_FUNCTION
#endif #endif
/* Static assertions, based on source found in LuaJIT's src/lj_def.h. */
#define EDUKE32_ASSERT_NAME2(name, line) name ## line
#define EDUKE32_ASSERT_NAME(line) EDUKE32_ASSERT_NAME2(eduke32_assert_, line)
#ifdef __COUNTER__ #ifdef __COUNTER__
# define EDUKE32_STATIC_ASSERT(cond) \ # define EDUKE32_UNIQUE_SRC_ID __COUNTER__
extern void EDUKE32_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#else #else
# define EDUKE32_UNIQUE_SRC_ID __LINE__
#endif
#if CXXSTD >= 2017
# define EDUKE32_STATIC_ASSERT(cond) static_assert(cond)
#elif CXXSTD >= 2011 || CSTD >= 2011 || EDUKE32_MSVC_CXX_PREREQ(1600)
# define EDUKE32_STATIC_ASSERT(cond) static_assert(cond, "")
#else
/* C99 / C++03 static assertions based on source found in LuaJIT's src/lj_def.h. */
# define EDUKE32_ASSERT_NAME2(name, line) name ## line
# define EDUKE32_ASSERT_NAME(line) EDUKE32_ASSERT_NAME2(eduke32_assert_, line)
# define EDUKE32_STATIC_ASSERT(cond) \ # define EDUKE32_STATIC_ASSERT(cond) \
extern void EDUKE32_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1]) extern void EDUKE32_ASSERT_NAME(EDUKE32_UNIQUE_SRC_ID)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER