Fix broken BLI_STATIC_ASSERT on Visual Studio.

The old trick seems to no longer work in newer VS version.
This commit is contained in:
Brecht Van Lommel 2019-04-02 15:49:07 +02:00
parent 4f4cea727e
commit d986b04bd3
Notes: blender-bot 2023-02-14 08:59:10 +01:00
Referenced by issue #63472, Cursed blend file crashes on F12 render unless SSS is turned off.
Referenced by issue #63346, diffuse_ramp closures of OSL scripts are not rendered (2.80)
Referenced by issue #63281, Drivers inside nodegroups inside nodegroups don't show up in Driver Editor
1 changed files with 13 additions and 18 deletions

View File

@ -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) \