NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
调试与断言

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

struct  neforce::source_location
 源码位置信息 更多...

宏定义

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

函数

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

详细描述

调试和断言工具

宏定义说明

◆ NEFORCE_CONSTEXPR_ASSERT

#define NEFORCE_CONSTEXPR_ASSERT ( COND)
值:
do { \
if (_NEFORCE is_constant_evaluated() && !bool(COND)) { \
_NEFORCE unreachable(); \
} \
} while (false);

编译时常量断言

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

在文件 debug.hpp47 行定义.

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

函数说明

◆ breakpoint()

void neforce::breakpoint ( )
inlinenoexcept

触发调试断点

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

在文件 debug.hpp109 行定义.

引用了 breakpoint().

被这些函数引用 breakpoint() , 以及 breakpoint_if_debugging().

◆ breakpoint_if_debugging()

void neforce::breakpoint_if_debugging ( )
inline

如果正在调试则触发断点

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

在文件 debug.hpp137 行定义.

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

被这些函数引用 breakpoint_if_debugging().

◆ debug_assert()

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

调试断言

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

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

引用了 debug_assert().

被这些函数引用 debug_assert().

◆ is_constant_evaluated()

bool neforce::is_constant_evaluated ( )
inlinenodiscardconstexprnoexcept

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

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

用于区分编译时和运行时

在文件 debug.hpp83 行定义.

引用了 is_constant_evaluated().

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

◆ is_debugger_present()

bool neforce::is_debugger_present ( )

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

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

引用了 is_debugger_present().

被这些函数引用 breakpoint_if_debugging() , 以及 is_debugger_present().

◆ unreachable()

void neforce::unreachable ( )
inlinenoexcept

标记不可达代码路径

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

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

在文件 debug.hpp68 行定义.

引用了 unreachable().

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