IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
assert_core.hxx
Go to the documentation of this file.
1
3
4#pragma once
6
7#include <assert.h>
8#include <cassert>
9#undef assert
10
11namespace ice::detail
12{
13
14 // The following function will fail to access element at index [2] only in constexpr scenarios and when the expression is false.
15 // This is good enough for us to create an assertion macro for constexpr and non-constexpr cases.
16 constexpr char _iceshard_constexpr_assert(bool v) noexcept
17 {
18 int cev = std::is_constant_evaluated();
19 char constexpr_assert_failure[2]{ };
20 return constexpr_assert_failure[!v + cev];
21 };
22
23} // namespace ice::detail::assert
24
25#if ISP_WINDOWS
26
27#define ICE_ASSERT_CORE(expression) do { if (std::is_constant_evaluated() == false) { \
28 (void)( \
29 (!!(expression)) || \
30 (_wassert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)), 0) \
31 ); } else { ice::detail::_iceshard_constexpr_assert(expression); } } while(false)
32
33#elif ISP_WEBAPP || ISP_LINUX
34
35#define ICE_ASSERT_CORE(expression) do { if (std::is_constant_evaluated() == false) { \
36 ((expression) \
37 ? (void)0 \
38 : __assert_fail(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__)); \
39 } else { ice::detail::_iceshard_constexpr_assert(expression); } } while(false)
40
41#else
42
43#define ICE_ASSERT_CORE(expression) do { if (std::is_constant_evaluated() == false) { \
44 ((expression) \
45 ? __assert_no_op \
46 : __assert2(__FILE__, __LINE__, __PRETTY_FUNCTION__, #expression)); \
47 } else { ice::detail::_iceshard_constexpr_assert(expression); } } while(false)
48
49#endif
Definition hashmap_details.hxx:13
constexpr char _iceshard_constexpr_assert(bool v) noexcept
Definition assert_core.hxx:16