Skip to content

Commit 2506b1a

Browse files
refactor(wheel_utils): restructure assertion macros with fallback handling
Reorganize preprocessor conditions for not_null assertion functionality and add fallback definition when WHEEL_ASSERTION is disabled. This ensures the not_null macro has a safe no-op fallback when assertions are not enabled.
1 parent 8dff898 commit 2506b1a

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

wheel_utils/include/wheel_utils/logging.hxx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,26 @@ WHEEL_UTILS_NAMESPACE
3131
#define WHEEL_BASE_NAME(path) ((std::strrchr(path, '/')) ? std::strrchr(path, '/') + 1 : path)
3232
#endif
3333

34-
#if !defined (WHEEL_NO_FAIL_FAST)
35-
#define NOT_NULL_CONTEXT void
36-
37-
#else
38-
#define NOT_NULL_CONTEXT bool
34+
#if defined (WHEEL_ASSERTION) && defined (WHEEL_EXPERIMENT)
35+
#if !defined (WHEEL_NO_FAIL_FAST)
36+
#define NOT_NULL_CONTEXT void
37+
#else
38+
#define NOT_NULL_CONTEXT bool
39+
#endif
3940
#endif
4041

4142
#if defined(WHEEL_ASSERTION)
42-
#if CURRENT_CPP_VERSION < 202002L && defined (WHEEL_SOURCE_LOCATION)
43+
#if defined (WHEEL_ASSERTION)
44+
#define USE_WHEEL_ASSERTION using wheel_utils::not_null;
45+
#else
46+
#define USE_WHEEL_ASSERTION static_assert(true, "WHEEL_ASSERTION has been disabled.");
47+
#endif
48+
49+
#if CURRENT_CPP_VERSION < 202002L && defined(WHEEL_SOURCE_LOCATION)
4350
#error "WHEEL_SOURCE_LOCATION only supports C++ version >= 20"
4451
#endif
45-
46-
#if defined (WHEEL_SOURCE_LOCATION)
52+
53+
#if defined(WHEEL_SOURCE_LOCATION) && !defined(WHEEL_EXPERIMENT)
4754
#include <type_traits>
4855
#include <source_location>
4956

@@ -62,7 +69,7 @@ WHEEL_UTILS_NAMESPACE
6269
}
6370
#endif
6471

65-
#if defined (WHEEL_EXPERIMENT)
72+
#if defined(WHEEL_EXPERIMENT)
6673
template<typename T>
6774
struct is_pointer {
6875
static const bool value = false;
@@ -83,9 +90,8 @@ WHEEL_UTILS_NAMESPACE
8390
if (ptr == nullptr) {
8491
::std::cerr << "Null pointer is not allowed in this context.\n";
8592

86-
#if !defined (WHEEL_NO_FAIL_FAST)
93+
#if !defined(WHEEL_NO_FAIL_FAST)
8794
::std::abort();
88-
8995
#else
9096
return false;
9197
#endif
@@ -109,6 +115,9 @@ WHEEL_UTILS_NAMESPACE
109115
}
110116
}
111117
#endif
118+
119+
#else
120+
#define not_null(T) (void)0
112121
#endif
113122

114123
#if defined(WHEEL_DEBUG)

0 commit comments

Comments
 (0)