summaryrefslogtreecommitdiff
path: root/src/assert.hh
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2017-02-19 17:37:32 +0300
committerFrank LENORMAND <lenormf@gmail.com>2017-02-22 13:04:25 +0300
commit98cfbc7c3c6a533f3202cdee10019774daaa0b07 (patch)
tree5a3ef08dea5ca6497660cce1e04099b9581bf74b /src/assert.hh
parentfb57734820f2f63c18bad095201d601fdcaab31c (diff)
Properly wrap `kak_assert` into a do-while scope
Expanding the `kak_assert` macro to either an `if` statement or nothing leads to issues when the macro is used in a conditional statement that doesn't use braces. Example: ncurses_ui.cc:476, in non debug mode, the macro will expand to an empty line, resulting in the `ungetch` call not being executed if the `ioctl` call succeeds (line 448).
Diffstat (limited to 'src/assert.hh')
-rw-r--r--src/assert.hh7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/assert.hh b/src/assert.hh
index 4d6c3782..406420d8 100644
--- a/src/assert.hh
+++ b/src/assert.hh
@@ -17,12 +17,13 @@ void on_assert_failed(const char* message);
#define TOSTRING(X) STRINGIFY(X)
#ifdef KAK_DEBUG
- #define kak_assert(...) \
+ #define kak_assert(...) do { \
if (not (__VA_ARGS__)) \
on_assert_failed("assert failed \"" #__VA_ARGS__ \
- "\" at " __FILE__ ":" TOSTRING(__LINE__))
+ "\" at " __FILE__ ":" TOSTRING(__LINE__)); \
+ } while (0)
#else
- #define kak_assert(...)
+ #define kak_assert(...) do {} while (0)
#endif