diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-04-02 16:49:07 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-04-02 17:00:52 +0300 |
commit | d986b04bd3021df107667c7cf74b31a27dbc443a (patch) | |
tree | b921bd4648ec4b802d8a30517fb4c987c2b848bc /source/blender/blenlib/BLI_assert.h | |
parent | 4f4cea727efdeaf388de7ce84a6a6c399050c590 (diff) |
Fix broken BLI_STATIC_ASSERT on Visual Studio.
The old trick seems to no longer work in newer VS version.
Diffstat (limited to 'source/blender/blenlib/BLI_assert.h')
-rw-r--r-- | source/blender/blenlib/BLI_assert.h | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/source/blender/blenlib/BLI_assert.h b/source/blender/blenlib/BLI_assert.h index b6d5242ae57..3454b236fca 100644 --- a/source/blender/blenlib/BLI_assert.h +++ b/source/blender/blenlib/BLI_assert.h @@ -34,6 +34,10 @@ extern "C" { #include <stdio.h> #endif +#ifdef _MSC_VER +#include <crtdbg.h> /* for _STATIC_ASSERT */ +#endif + /* BLI_assert(), default only to print * for aborting need to define WITH_ASSERT_ABORT */ @@ -72,24 +76,15 @@ extern "C" { (!defined(__COVERITY__)) && \ (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */ # define BLI_STATIC_ASSERT(a, msg) __extension__ _Static_assert(a, msg); -#else -/* Code adapted from http://www.pixelbeat.org/programming/gcc/static_assert.html */ -/* Note we need the two concats below because arguments to ## are not expanded, so we need to - * expand __LINE__ with one indirection before doing the actual concatenation. */ -# define _BLI_ASSERT_CONCAT_(a, b) a##b -# define _BLI_ASSERT_CONCAT(a, b) _BLI_ASSERT_CONCAT_(a, b) - /* These can't be used after statements in c89. */ -# if defined(__COUNTER__) /* MSVC */ -# define BLI_STATIC_ASSERT(a, msg) \ - ; enum { _BLI_ASSERT_CONCAT(static_assert_, __COUNTER__) = 1 / (int)(!!(a)) }; -# else /* older gcc, clang... */ - /* This can't be used twice on the same line so ensure if using in headers - * that the headers are not included twice (by wrapping in #ifndef...#endif) - * Note it doesn't cause an issue when used on same line of separate modules - * compiled with gcc -combine -fwhole-program. */ -# define BLI_STATIC_ASSERT(a, msg) \ - ; enum { _BLI_ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; -# endif +#elif defined(_MSC_VER) +# define BLI_STATIC_ASSERT(a, msg) _STATIC_ASSERT(a); +#else /* older gcc, clang... */ + /* This can't be used twice on the same line so ensure if using in headers + * that the headers are not included twice (by wrapping in #ifndef...#endif) + * Note it doesn't cause an issue when used on same line of separate modules + * compiled with gcc -combine -fwhole-program. */ +# define BLI_STATIC_ASSERT(a, msg) \ + ; enum { _BLI_ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; #endif #define BLI_STATIC_ASSERT_ALIGN(st, align) \ |