diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-08-08 10:39:26 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-08-08 10:39:26 +0900 |
| commit | c849b894edbf5bb170721e836bbef514fb74d074 (patch) | |
| tree | 118376f23da63a81d9d141e2a0352ea37c1eb450 /include | |
| parent | d8e060d2d3391b734f40b812651a171762de1c3b (diff) | |
| download | mruby-c849b894edbf5bb170721e836bbef514fb74d074.tar.gz mruby-c849b894edbf5bb170721e836bbef514fb74d074.zip | |
Reintroduce `mrb_static_assert`; #5051
Note that the home brew version of `mrb_static_assert` only works within
the function body. This reverts commit 8f99689.
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/include/mruby.h b/include/mruby.h index 5bbfbb1ad..5aced9ca7 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -62,11 +62,17 @@ #define mrb_assert_int_fit(t1,n,t2,max) ((void)0) #endif -#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L -#define mrb_static_assert(exp, str) _Static_assert(exp, str) +#if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || \ + (defined __cplusplus && __cplusplus >= 201103L) +# include <assert.h> +# define mrb_static_assert(exp, str) static_assert(exp, str) #else -#define mrb_static_assert(exp, str) +/* C version of static_assert() */ +# define mrb_static_assert(cond, str) \ + do { int assertion_failed[(cond) ? 1 : -1];\ + (void) assertion_failed; } while(0) #endif +#define mrb_static_assert1(exp) mrb_static_assert(exp, #exp) #include "mrbconf.h" |
