diff options
author | Michel Hermier <michel.hermier@gmail.com> | 2021-12-14 17:44:43 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-23 17:53:46 -0800 |
commit | 682f89d5bc1fbc28260ccf98f4ebc7798a5cd46c (patch) | |
tree | 61e6bd22f79b5e9da5d4e497ade0f45553b33a06 /Userland/Libraries/LibC | |
parent | 7b8398ea0d68056e4fee0c97f0eb3ad19d33d560 (diff) | |
download | serenity-682f89d5bc1fbc28260ccf98f4ebc7798a5cd46c.zip |
LibC: Allow multiple includes of `<assert.h>`
ISO C requires in section 7.2:
The assert macro is redefined according to the current state of NDEBUG
each time that <assert.h> is included.
Also add tests for `assert` multiple inclusion accordingly.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r-- | Userland/Libraries/LibC/assert.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Userland/Libraries/LibC/assert.h b/Userland/Libraries/LibC/assert.h index 86c042281c..c64b51ecd0 100644 --- a/Userland/Libraries/LibC/assert.h +++ b/Userland/Libraries/LibC/assert.h @@ -4,16 +4,25 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#pragma once +#ifndef _ASSERT_H +# define _ASSERT_H + +# define __stringify_helper(x) # x +# define __stringify(x) __stringify_helper(x) + +# ifndef __cplusplus +# define static_assert _Static_assert +# endif +#endif #include <sys/cdefs.h> +#undef assert + __BEGIN_DECLS #ifndef NDEBUG __attribute__((noreturn)) void __assertion_failed(const char* msg); -# define __stringify_helper(x) # x -# define __stringify(x) __stringify_helper(x) # define assert(expr) \ (__builtin_expect(!(expr), 0) \ ? __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \ @@ -23,8 +32,4 @@ __attribute__((noreturn)) void __assertion_failed(const char* msg); # define assert(expr) ((void)(0)) #endif -#ifndef __cplusplus -# define static_assert _Static_assert -#endif - __END_DECLS |