Add a smoke test to Span in debug builds to recover from non-empty nullptr Span.

This commit is contained in:
Lukas Tenbrink
2025-06-12 11:45:50 +02:00
parent d9cd011e2f
commit 2d0ff9774d
2 changed files with 15 additions and 6 deletions

View File

@@ -51,8 +51,17 @@ public:
std::is_same<T, wchar_t>>;
_FORCE_INLINE_ constexpr Span() = default;
_FORCE_INLINE_ constexpr Span(const T *p_ptr, uint64_t p_len) :
_ptr(p_ptr), _len(p_len) {}
_FORCE_INLINE_ Span(const T *p_ptr, uint64_t p_len) :
_ptr(p_ptr), _len(p_len) {
#ifdef DEBUG_ENABLED
// TODO In c++20, make this check run only in non-consteval, and make this constructor constexpr.
if (_ptr == nullptr && _len > 0) {
ERR_PRINT("Internal bug, please report: Span was created from nullptr with size > 0. Recovering by using size = 0.");
_len = 0;
}
#endif
}
// Allows creating Span directly from C arrays and string literals.
template <size_t N>