From 2040190fb6da7af2482388d2617fb30c55fe153c Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 30 Mar 2019 22:58:08 +0000 Subject: [PATCH] utils: improve CHECK() macro Include the original expression in the assertion failure message. Signed-off-by: Yuxuan Shui --- src/utils.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.h b/src/utils.h index 2b443c4..3fea66d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -41,12 +41,13 @@ safe_isnan(double a) { assert(false); \ abort(); \ } while (0) +#define CHECK_EXPR(...) ((void)0) /// Same as assert, but evaluates the expression even in release builds #define CHECK(expr) \ do { \ - __auto_type __tmp = (expr); \ - assert(__tmp); \ - (void)__tmp; \ + __auto_type _ = (expr); \ + assert((CHECK_EXPR(expr), _)); \ + (void)_; \ } while (0) // Some macros for checked cast