[Bf-blender-cvs] [d986b04bd30] master: Fix broken BLI_STATIC_ASSERT on Visual Studio.

Brecht Van Lommel noreply at git.blender.org
Tue Apr 2 16:01:31 CEST 2019


Commit: d986b04bd3021df107667c7cf74b31a27dbc443a
Author: Brecht Van Lommel
Date:   Tue Apr 2 15:49:07 2019 +0200
Branches: master
https://developer.blender.org/rBd986b04bd3021df107667c7cf74b31a27dbc443a

Fix broken BLI_STATIC_ASSERT on Visual Studio.

The old trick seems to no longer work in newer VS version.

===================================================================

M	source/blender/blenlib/BLI_assert.h

===================================================================

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



More information about the Bf-blender-cvs mailing list