tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
assert.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_CASSERT_ASSERT_HPP
4
#define TETL_CASSERT_ASSERT_HPP
5
6
#include <
etl/_config/all.hpp
>
7
8
#include <
etl/_utility/ignore_unused.hpp
>
9
#include <
etl/_version/implementation.hpp
>
10
11
#if __has_include(<stdlib.h>)
12
#include <stdlib.h>
13
14
#include <
etl/_config/_workarounds/001_avr_macros.hpp
>
// For AVR macros
15
#else
16
inline
auto
exit
(
int
/*ignore*/
) ->
void
{ }
17
#endif
18
19
namespace
etl
{
21
struct
assert_msg
{
22
int
line
{};
23
char
const
*
file
{
nullptr
};
24
char
const
*
func
{
nullptr
};
25
char
const
*
expression
{
nullptr
};
26
};
27
28
}
// namespace etl
29
30
namespace
etl
{
31
#if defined(TETL_ENABLE_CUSTOM_ASSERT_HANDLER)
32
33
template
<
typename
Assertion>
34
[[noreturn]]
auto
assert_handler
(Assertion
const
& msg) -> void;
// NOLINT
35
36
#else
37
38
template
<
typename
Assertion>
39
[[noreturn]]
auto
assert_handler
(Assertion
const
& msg) ->
void
// NOLINT
40
{
41
etl::ignore_unused
(msg);
42
::exit
(1);
// NOLINT
43
}
44
45
#endif
46
47
}
// namespace etl
48
49
#define TETL_ASSERT_IMPL(...) \
50
do { \
51
if (not(__VA_ARGS__)) [[unlikely]] { \
52
/* TETL_DEBUG_TRAP(); */
\
53
etl::assert_handler(etl::assert_msg{ \
54
.line = __LINE__, \
55
.file = __FILE__, \
56
.func = etl::is_hosted() ? TETL_BUILTIN_FUNCTION() : nullptr, \
57
.expression = etl::is_hosted() ? TETL_STRINGIFY((__VA_ARGS__)) : nullptr, \
58
}); \
59
} \
60
} while (false)
61
62
#if not defined(TETL_NDEBUG) or (TETL_NDEBUG == 0) or defined(TETL_ENABLE_ASSERTIONS)
63
#define TETL_ASSERT(...) TETL_ASSERT_IMPL(__VA_ARGS__)
64
#else
65
#define TETL_ASSERT(...)
66
#endif
67
68
#endif
// TETL_CASSERT_ASSERT_HPP
001_avr_macros.hpp
all.hpp
exit
auto exit(int) -> void
Definition
assert.hpp:16
ignore_unused.hpp
implementation.hpp
etl
Definition
adjacent_find.hpp:8
etl::ignore_unused
constexpr auto ignore_unused(Types &&...) -> void
Explicitly ignore arguments or variables.
Definition
ignore_unused.hpp:17
etl::assert_handler
auto assert_handler(Assertion const &msg) -> void
Definition
assert.hpp:39
etl::assert_msg
Payload for an assertion.
Definition
assert.hpp:21
etl::assert_msg::line
int line
Definition
assert.hpp:22
etl::assert_msg::expression
char const * expression
Definition
assert.hpp:25
etl::assert_msg::file
char const * file
Definition
assert.hpp:23
etl::assert_msg::func
char const * func
Definition
assert.hpp:24
include
etl
_cassert
assert.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0