WPILibC++ 2025.3.2
Loading...
Searching...
No Matches
assert.hpp
Go to the documentation of this file.
1// Copyright (C) 2015-2023 Jonathan Müller and foonathan/memory contributors
2// SPDX-License-Identifier: Zlib
3
4#ifndef WPI_MEMORY_DETAIL_ASSERT_HPP_INCLUDED
5#define WPI_MEMORY_DETAIL_ASSERT_HPP_INCLUDED
6
7#include <cstdlib>
8
9#include "../config.hpp"
10
11namespace wpi
12{
13 namespace memory
14 {
15 namespace detail
16 {
17 // handles a failed assertion
18 void handle_failed_assert(const char* msg, const char* file, int line,
19 const char* fnc) noexcept;
20
21 void handle_warning(const char* msg, const char* file, int line,
22 const char* fnc) noexcept;
23
24// note: debug assertion macros don't use fully qualified name
25// because they should only be used in this library, where the whole namespace is available
26// can be override via command line definitions
27#if WPI_MEMORY_DEBUG_ASSERT && !defined(WPI_MEMORY_ASSERT)
28#define WPI_MEMORY_ASSERT(Expr) \
29 static_cast<void>((Expr) \
30 || (detail::handle_failed_assert("Assertion \"" #Expr "\" failed", __FILE__, \
31 __LINE__, __func__), \
32 true))
33
34#define WPI_MEMORY_ASSERT_MSG(Expr, Msg) \
35 static_cast<void>((Expr) \
36 || (detail::handle_failed_assert("Assertion \"" #Expr "\" failed: " Msg, \
37 __FILE__, __LINE__, __func__), \
38 true))
39
40#define WPI_MEMORY_UNREACHABLE(Msg) \
41 detail::handle_failed_assert("Unreachable code reached: " Msg, __FILE__, __LINE__, __func__)
42
43#define WPI_MEMORY_WARNING(Msg) detail::handle_warning(Msg, __FILE__, __LINE__, __func__)
44
45#elif !defined(WPI_MEMORY_ASSERT)
46#define WPI_MEMORY_ASSERT(Expr)
47#define WPI_MEMORY_ASSERT_MSG(Expr, Msg)
48#define WPI_MEMORY_UNREACHABLE(Msg) std::abort()
49#define WPI_MEMORY_WARNING(Msg)
50#endif
51 } // namespace detail
52 } // namespace memory
53} // namespace wpi
54
55#endif // WPI_MEMORY_DETAIL_ASSERT_HPP_INCLUDED
56
Configuration macros.
detail namespace with internal helper functions
Definition input_adapters.h:32
void handle_warning(const char *msg, const char *file, int line, const char *fnc) noexcept
void handle_failed_assert(const char *msg, const char *file, int line, const char *fnc) noexcept
Memory namespace.
Definition heap_allocator.hpp:20
Foonathan namespace.
Definition ntcore_cpp.h:26