llvm-project/libc/include/assert.h.def
Michael Jones 9124e963a3
[libc] Update assert for C23 (#137402)
Previously the assert macro took one argument named "e", but this led to
possible errors if the caller had commas in their input. C23 changed the
definition of assert to use `__VA_ARGS__` to ensure comma cases are
handled properly. This patch doesn't introduce the enforcement function
mentioned in the standard update, though that may be done in a followup.

Fixes #136184
2025-04-28 15:06:52 -04:00

33 lines
980 B
Modula-2

//===-- C standard library header assert.h --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "__llvm-libc-common.h"
#include "llvm-libc-macros/assert-macros.h"
// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.
#ifndef __cplusplus
#undef static_assert
#define static_assert _Static_assert
#endif
#undef assert
#ifdef NDEBUG
#define assert(...) ((void)0)
#else
#ifdef __cplusplus
extern "C"
#endif
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
#define assert(...) \
((__VA_ARGS__) ? ((void)0) : __assert_fail(#__VA_ARGS__, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#endif
%%public_api()