Prevent make_span from working with vectors and arrays of pointers (#8735)

* Prevent `make_span` from working with vectors and arrays of pointers

* support `make_structs_span` for little-endian

* fix build: add the required parentheses

---------

Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
are-you-tilted-already
2025-11-05 00:47:44 +03:00
committed by GitHub
parent 592dc50037
commit 5ed02dc04a
2 changed files with 39 additions and 4 deletions

View File

@@ -39,10 +39,11 @@ class Array {
typedef VectorConstIterator<T, return_type, uoffset_t> const_iterator;
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
// If T is a LE-scalar or a struct (!scalar_tag::value).
// If T is a non-pointer and a LE-scalar or a struct (!scalar_tag::value).
static FLATBUFFERS_CONSTEXPR bool is_span_observable =
(scalar_tag::value && (FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1)) ||
!scalar_tag::value;
!std::is_pointer<T>::value &&
((scalar_tag::value && (FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1)) ||
!scalar_tag::value);
FLATBUFFERS_CONSTEXPR uint16_t size() const { return length; }