Fix static_assert failure for zero-length array

The recursive template implemented for `validate_size` does not support
incomplete types, like zero-length array.

By splitting the `validate_size` struct in two parts:
1. `validate_size_eq` that does the actual size check, and
2. `validate_size` that preserves the previous interface and inherit
   from `validate_size_eq`,
we get the same interface and feature than previously, but without the
recursive template that doesn't support incomplete types.
This commit is contained in:
Thierry Treyer 2024-01-10 07:07:47 -08:00 committed by Thierry Treyer
parent cbeafba9bb
commit fba0d527fd

View File

@ -160,15 +160,14 @@ template <typename T, int32_t Id>
struct DummyAllocator<T, 0, 1, Id> struct DummyAllocator<T, 0, 1, Id>
: DummyAllocatorBase<DummyAllocator, T, 0, 1, Id> {}; : DummyAllocatorBase<DummyAllocator, T, 0, 1, Id> {};
template <typename Type, size_t ExpectedSize, size_t ActualSize = 0> template <typename Type, size_t ExpectedSize, size_t ActualSize>
struct validate_size { struct validate_size_eq {
static constexpr bool value = true; static constexpr bool value = true;
static_assert(ExpectedSize == ActualSize); static_assert(ExpectedSize == ActualSize);
}; };
template <typename Type, size_t ExpectedSize> template <typename Type, size_t ExpectedSize>
struct validate_size<Type, ExpectedSize> struct validate_size : validate_size_eq<Type, ExpectedSize, sizeof(Type)> {};
: validate_size<Type, ExpectedSize, sizeof(Type)> {};
template <size_t ExpectedOffset, size_t ActualOffset> template <size_t ExpectedOffset, size_t ActualOffset>
struct validate_offset { struct validate_offset {