common: Turn assertions into expressions.
authorJustus Winter <justus@g10code.com>
Mon, 2 Jan 2017 15:30:45 +0000 (16:30 +0100)
committerJustus Winter <justus@g10code.com>
Mon, 2 Jan 2017 17:23:34 +0000 (18:23 +0100)
* common/logging.h (log_assert): Turn this into an expression so it
can be used in expressions.

Signed-off-by: Justus Winter <justus@g10code.com>
common/logging.h

index 64b999d..fc9e846 100644 (file)
@@ -56,18 +56,18 @@ estream_t log_get_stream (void);
   void _log_assert (const char *expr, const char *file, int line,
                     const char *func) GPGRT_ATTR_NORETURN;
 # define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__)
-# define log_assert(expr)    do {                               \
-    if (!(expr))                                                \
-      _log_assert (#expr, __FILE__, __LINE__, __FUNCTION__);    \
-  } while (0)
+# define log_assert(expr)                                       \
+  ((expr)                                                       \
+   ? (void) 0                                                   \
+   : _log_assert (#expr, __FILE__, __LINE__, __FUNCTION__))
 #else /*!GPGRT_HAVE_MACRO_FUNCTION*/
   void bug_at (const char *file, int line);
   void _log_assert (const char *expr, const char *file, int line;
 # define BUG() bug_at( __FILE__ , __LINE__ )
-# define log_assert(expr)    do {                               \
-    if (!(expr))                                                \
-      _log_assert (#expr, __FILE__, __LINE__);                  \
-  } while (0)
+# define log_assert(expr)                                       \
+  ((expr)                                                       \
+   ? (void) 0                                                   \
+   : _log_assert (#expr, __FILE__, __LINE__))
 #endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
 
 /* Flag values for log_set_prefix. */