From c16bd951cdff8d9dd4ba44e4634cb284c6f09342 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 30 Mar 2014 15:02:24 +1100 Subject: Enable GCC pedantic warnings with strict flags, also modify MIN/MAX macros to prevent shadowing. --- intern/guardedalloc/intern/mallocn_guarded_impl.c | 2 +- source/blender/blenlib/BLI_strict_flags.h | 1 + source/blender/blenlib/BLI_utildefines.h | 46 +++++++++++++++-------- source/blender/blenlib/intern/rand.c | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c index 7a8545de524..724e7f95845 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.c +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c @@ -735,7 +735,7 @@ static void MEM_guarded_printmemlist_internal(int pydict) membl->_count); #else print_error("%s len: " SIZET_FORMAT " %p\n", - membl->name, SIZET_ARG(membl->len), membl + 1); + membl->name, SIZET_ARG(membl->len), (void *)(membl + 1)); #endif #ifdef DEBUG_BACKTRACE print_memhead_backtrace(membl); diff --git a/source/blender/blenlib/BLI_strict_flags.h b/source/blender/blenlib/BLI_strict_flags.h index cb92f7837ec..ce39078ea73 100644 --- a/source/blender/blenlib/BLI_strict_flags.h +++ b/source/blender/blenlib/BLI_strict_flags.h @@ -28,6 +28,7 @@ */ #ifdef __GNUC__ +# pragma GCC diagnostic error "-Wpedantic" # pragma GCC diagnostic error "-Wsign-conversion" # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 /* gcc4.6+ only */ # pragma GCC diagnostic error "-Wsign-compare" diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index bb1b3a368f0..46553ccc0fc 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -50,26 +50,42 @@ /* min/max */ #if defined(__GNUC__) || defined(__clang__) -#define MIN2(x, y) ({ \ - typeof(x) x_ = (x); \ - typeof(y) y_ = (y); \ - ((x_) < (y_) ? (x_) : (y_)); }) +#define MIN2(a, b) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); \ + ((a_) < (b_) ? (a_) : (b_)); }) -#define MAX2(x, y) ({ \ - typeof(x) x_ = (x); \ - typeof(y) y_ = (y); \ - ((x_) > (y_) ? (x_) : (y_)); }) +#define MAX2(a, b) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); \ + ((a_) > (b_) ? (a_) : (b_)); }) + +#define MIN3(a, b, c) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); \ + ((a_ < b_) ? ((a_ < c_) ? a_ : c_) : ((b_ < c_) ? b_ : c_)); }) + +#define MAX3(a, b, c) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); \ + ((a_ > b_) ? ((a_ > c_) ? a_ : c_) : ((b_ > c_) ? b_ : c_)); }) + +#define MIN4(a, b, c, d) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); typeof(d) d_ = (d); \ + ((a_ < b_) ? ((a_ < c_) ? ((a_ < d_) ? a_ : d_) : ((c_ < d_) ? c_ : d_)) : \ + ((b_ < c_) ? ((b_ < d_) ? b_ : d_) : ((c_ < d_) ? c_ : d_))); }) + +#define MAX4(a, b, c, d) __extension__ ({ \ + typeof(a) a_ = (a); typeof(b) b_ = (b); typeof(c) c_ = (c); typeof(d) d_ = (d); \ + ((a_ > b_) ? ((a_ > c_) ? ((a_ > d_) ? a_ : d_) : ((c_ > d_) ? c_ : d_)) : \ + ((b_ > c_) ? ((b_ > d_) ? b_ : d_) : ((c_ > d_) ? c_ : d_))); }) #else -#define MIN2(x, y) ((x) < (y) ? (x) : (y)) -#define MAX2(x, y) ((x) > (y) ? (x) : (y)) -#endif +#define MIN2(a, b) ((a) < (b) ? (a) : (b)) +#define MAX2(a, b) ((a) > (b) ? (a) : (b)) -#define MIN3(x, y, z) (MIN2(MIN2((x), (y)), (z))) -#define MIN4(x, y, z, a) (MIN2(MIN2((x), (y)), MIN2((z), (a)))) +#define MIN3(a, b, c) (MIN2(MIN2((a), (b)), (c))) +#define MIN4(a, b, c, d) (MIN2(MIN2((a), (b)), MIN2((c), (d)))) -#define MAX3(x, y, z) (MAX2(MAX2((x), (y)), (z))) -#define MAX4(x, y, z, a) (MAX2(MAX2((x), (y)), MAX2((z), (a)))) +#define MAX3(a, b, c) (MAX2(MAX2((a), (b)), (c))) +#define MAX4(a, b, c, d) (MAX2(MAX2((a), (b)), MAX2((c), (d)))) +#endif /* min/max that return a value of our choice */ #define MAX3_PAIR(cmp_a, cmp_b, cmp_c, ret_a, ret_b, ret_c) \ diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 25a1a528db4..0afa4f81dba 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -200,7 +200,7 @@ float BLI_frand(void) void BLI_frand_unit_v3(float v[3]) { - return BLI_rng_get_float_unit_v3(&theBLI_rng, v); + BLI_rng_get_float_unit_v3(&theBLI_rng, v); } float BLI_hash_frand(unsigned int seed) -- cgit v1.2.3