Skip to content

Commit

Permalink
LibC: Replace use of do/while in assert() with the ternary operator
Browse files Browse the repository at this point in the history
It's a single expression, no do/while needed. This makes assert() work
with the comma operator (assert(foo), assert(bar), assert(baz)).
Found because exactly this is being used somewhere in the guts of LLVM.
  • Loading branch information
linusg committed Jul 12, 2021
1 parent 0c7a319 commit 15d5c62
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Userland/Libraries/LibC/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ __BEGIN_DECLS
__attribute__((noreturn)) void __assertion_failed(const char* msg);
# define __stringify_helper(x) # x
# define __stringify(x) __stringify_helper(x)
# define assert(expr) \
do { \
if (__builtin_expect(!(expr), 0)) \
__assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)); \
} while (0)
# define assert(expr) \
(__builtin_expect(!(expr), 0) \
? __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \
: void(0))

#else
# define assert(expr) ((void)(0))
# define VERIFY_NOT_REACHED() _abort()
Expand Down

0 comments on commit 15d5c62

Please sign in to comment.