Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#ifndef _ASSERT_H
8# define _ASSERT_H
9
10# define __stringify_helper(x) #x
11# define __stringify(x) __stringify_helper(x)
12
13# ifndef __cplusplus
14# define static_assert _Static_assert
15# endif
16#endif
17
18#include <sys/cdefs.h>
19
20#undef assert
21
22__BEGIN_DECLS
23
24#ifndef NDEBUG
25__attribute__((noreturn)) void __assertion_failed(char const* msg);
26# define assert(expr) \
27 (__builtin_expect(!(expr), 0) \
28 ? __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \
29 : (void)0)
30
31#else
32# define assert(expr) ((void)(0))
33#endif
34
35__END_DECLS