Add a smoke test to Span
in debug builds to recover from non-empty nullptr
Span
.
This commit is contained in:
parent
d9cd011e2f
commit
2d0ff9774d
@ -51,8 +51,17 @@ public:
|
|||||||
std::is_same<T, wchar_t>>;
|
std::is_same<T, wchar_t>>;
|
||||||
|
|
||||||
_FORCE_INLINE_ constexpr Span() = default;
|
_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.
|
// Allows creating Span directly from C arrays and string literals.
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
|
@ -43,10 +43,10 @@ TEST_CASE("[Span] Constexpr Validators") {
|
|||||||
static_assert(span_empty.is_empty());
|
static_assert(span_empty.is_empty());
|
||||||
|
|
||||||
constexpr static uint16_t value = 5;
|
constexpr static uint16_t value = 5;
|
||||||
constexpr Span<uint16_t> span_value(&value, 1);
|
Span<uint16_t> span_value(&value, 1);
|
||||||
static_assert(span_value.ptr() == &value);
|
CHECK(span_value.ptr() == &value);
|
||||||
static_assert(span_value.size() == 1);
|
CHECK(span_value.size() == 1);
|
||||||
static_assert(!span_value.is_empty());
|
CHECK(!span_value.is_empty());
|
||||||
|
|
||||||
static constexpr int ints[] = { 0, 1, 2, 3, 4, 5 };
|
static constexpr int ints[] = { 0, 1, 2, 3, 4, 5 };
|
||||||
constexpr Span<int> span_array = ints;
|
constexpr Span<int> span_array = ints;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user