NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
调试与断言

调试断点和断言工具 更多...

宏定义

#define NEFORCE_CONSTEXPR_ASSERT(COND)
 编译时常量断言

函数

NEFORCE_NORETURN void unreachable () noexcept
 标记不可达代码路径
constexpr bool is_constant_evaluated () noexcept
 检查当前上下文是否在常量求值中
bool is_debugger_present ()
 检测当前进程是否正在被调试器附加
void debug_assert (bool condition, const char *message=nullptr)
 调试断言
void breakpoint () noexcept
 触发调试断点
void breakpoint_if_debugging ()
 如果正在调试则触发断点

详细描述

调试断点和断言工具

宏定义说明

◆ NEFORCE_CONSTEXPR_ASSERT

#define NEFORCE_CONSTEXPR_ASSERT ( COND)
值:
do { \
if (_NEFORCE is_constant_evaluated() && !bool(COND)) { \
_NEFORCE unreachable(); \
} \
} while (false);
constexpr bool is_constant_evaluated() noexcept
检查当前上下文是否在常量求值中
NEFORCE_NORETURN void unreachable() noexcept
标记不可达代码路径

编译时常量断言

在常量求值上下文中进行断言,如果条件为false则触发不可达代码。 仅在C++20及以上版本有效。

在文件 breakpoint.hpp47 行定义.

被这些函数引用 atomic_cmpexch_strong(), atomic_cmpexch_strong_any(), atomic_cmpexch_weak(), atomic_cmpexch_weak_any(), atomic_ref_base< Float, false, true >::atomic_ref_base(), atomic_ref_base< T, false, false >::atomic_ref_base(), atomic_ref_base< T, true, false >::atomic_ref_base(), atomic_semaphore< 1 >::atomic_semaphore(), memory_view< byte_t >::back(), atomic_flag::clear(), atomic_flag::clear(), atomic< T >::compare_exchange_strong(), atomic< T >::compare_exchange_strong(), atomic_base< T * >::compare_exchange_strong(), atomic_base< T * >::compare_exchange_strong(), atomic< T >::compare_exchange_weak(), atomic< T >::compare_exchange_weak(), atomic_base< T * >::compare_exchange_weak(), atomic_base< T * >::compare_exchange_weak(), memory_view< byte_t >::first(), memory_view< byte_t >::front(), memory_view< byte_t >::last(), latch::latch(), atomic_base< char >::load(), atomic_base< char >::load(), atomic_base< T * >::load(), atomic_base< T * >::load(), generator< T >::iterator::operator*(), memory_view< byte_t >::operator[](), atomic_base< char >::store(), atomic_base< char >::store(), atomic_base< T * >::store(), atomic_base< T * >::store() , 以及 memory_view< byte_t >::view().

函数说明

◆ breakpoint()

void breakpoint ( )
inlinenoexcept

触发调试断点

此函数会直接触发断点,无论是否有调试器附加。

在文件 breakpoint.hpp109 行定义.

被这些函数引用 breakpoint_if_debugging().

◆ breakpoint_if_debugging()

void breakpoint_if_debugging ( )
inline

如果正在调试则触发断点

首先检查是否有调试器附加,如果有则触发断点。 适用于条件性断点,避免在非调试环境中意外中断。

在文件 breakpoint.hpp137 行定义.

引用了 breakpoint() , 以及 is_debugger_present().

◆ debug_assert()

void debug_assert ( bool condition,
const char * message = nullptr )

调试断言

参数
condition条件表达式
message断言失败时的消息

当条件为false时,输出断言失败信息并触发调试断点(如果正在调试)。 仅在调试构建中有效,发布构建中此函数为空操作。

◆ is_constant_evaluated()

bool is_constant_evaluated ( )
inlinenodiscardconstexprnoexcept

检查当前上下文是否在常量求值中

返回
如果在常量求值上下文中返回true,否则返回false

用于区分编译时和运行时

在文件 breakpoint.hpp83 行定义.

被这些函数引用 allocate() , 以及 deallocate().

◆ is_debugger_present()

bool is_debugger_present ( )

检测当前进程是否正在被调试器附加

返回
如果正在调试则返回true,否则返回false

被这些函数引用 breakpoint_if_debugging().

◆ unreachable()

NEFORCE_NORETURN void unreachable ( )
inlinenoexcept

标记不可达代码路径

该函数用于向编译器指示当前代码路径永远不会被执行。当编译器遇到此调用时, 可以进行激进的优化,假设此后的代码永远不会运行。如果实际执行到了此函数, 将导致未定义行为(通常是程序崩溃或产生不可预测的结果)。

注解
此函数永远不会返回,调用后程序行为未定义。
警告
仅在确定代码路径绝对不可达时使用,否则会导致严重的运行时问题。

在文件 breakpoint.hpp68 行定义.

被这些函数引用 standard_allocator< U >::allocate(), any_cast(), meta_any::convert(), meta_any::get(), meta_any::get(), toml_datetime::get_string_value(), make_shared(), color::parse() , 以及 toml_datetime::toml_datetime().