1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___ASSERT
11#define _LIBCPP___ASSERT
12
13#include <__config>
14#include <iosfwd> // for std::string
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#  pragma GCC system_header
18#endif
19
20#if _LIBCPP_DEBUG_LEVEL >= 1
21#   define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : ::std::__libcpp_debug_function(::std::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
22#else
23#   define _LIBCPP_ASSERT(x, m) ((void)0)
24#endif
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
29  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
30  __libcpp_debug_info()
31      : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {}
32  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
33  __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m)
34    : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {}
35
36  _LIBCPP_FUNC_VIS string what() const;
37
38  const char* __file_;
39  int __line_;
40  const char* __pred_;
41  const char* __msg_;
42};
43
44/// __libcpp_debug_function_type - The type of the assertion failure handler.
45typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&);
46
47/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT
48///    fails.
49extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function;
50
51/// __libcpp_abort_debug_function - A debug handler that aborts when called.
52_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
53void __libcpp_abort_debug_function(__libcpp_debug_info const&);
54
55/// __libcpp_set_debug_function - Set the debug handler to the specified
56///    function.
57_LIBCPP_FUNC_VIS
58bool __libcpp_set_debug_function(__libcpp_debug_function_type __func);
59
60_LIBCPP_END_NAMESPACE_STD
61
62#endif // _LIBCPP___ASSERT
63