diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-12-08 12:54:56 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-12-08 12:54:56 +0300 |
commit | 3e7e97f1277d83582f314587f28f513291e2caca (patch) | |
tree | 8408974fd135fad7344decfd496badb80e04faa8 /source/blender/blenlib | |
parent | 690345a826544aec7a30b1d39966d867d093a8d1 (diff) |
BMesh: ensure iterator macros assign to valid types
note, this is for C++ code which expects a cast, (will be added later)
also add a macro for nop-expressions (EXPR_NOP),
when we never want an expression to be evaluated, but it should still be valid.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_compiler_typecheck.h | 19 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 2 |
2 files changed, 14 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_compiler_typecheck.h b/source/blender/blenlib/BLI_compiler_typecheck.h index 551569b066d..46c57772f64 100644 --- a/source/blender/blenlib/BLI_compiler_typecheck.h +++ b/source/blender/blenlib/BLI_compiler_typecheck.h @@ -51,9 +51,9 @@ })) #else -# define CHECK_TYPE(var, type) -# define CHECK_TYPE_PAIR(var_a, var_b) -# define CHECK_TYPE_PAIR_INLINE(var_a, var_b) (void)0 +# define CHECK_TYPE(var, type) { EXPR_NOP(var); }(void)0 +# define CHECK_TYPE_PAIR(var_a, var_b) { (EXPR_NOP(var_a), EXPR_NOP(var_b)); }(void)0 +# define CHECK_TYPE_PAIR_INLINE(var_a, var_b) (EXPR_NOP(var_a), EXPR_NOP(var_b)) #endif /* can be used in simple macros */ @@ -66,10 +66,15 @@ ((void)(((type)0) != (0 ? (val) : ((type)0)))) #endif -#define CHECK_TYPE_NONCONST(var) { \ - void *non_const = 0 ? (var) : NULL; \ - (void)non_const; \ -} (void)0 +#if defined(__GNUC__) || defined(__clang__) +# define CHECK_TYPE_NONCONST(var) __extension__ ({ \ + void *non_const = 0 ? (var) : NULL; \ + (void)non_const; \ +}) +#else +# define CHECK_TYPE_NONCONST(var) EXPR_NOP(var) +#endif + /** * CHECK_TYPE_ANY: handy macro, eg: diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index ef1312a1d94..53896bb31b6 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -219,6 +219,8 @@ extern "C" { /* reusable ELEM macro */ #define ELEM(...) VA_NARGS_CALL_OVERLOAD(_VA_ELEM, __VA_ARGS__) +/* no-op for expressions we don't want to instansiate, but must remian valid */ +#define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) /* shift around elements */ #define SHIFT3(type, a, b, c) { \ |