lamarrr/STX

Span allows undesirable conversions

melak47 opened this issue · 3 comments

Describe the bug
Span<Base> can be constructed from Span<Derived> (or some container of Derived), but iterating over (or indexing) into that Span<Base> will cause undefined behavior if sizeof(Base) != sizeof(Derived).

Expected behavior
The constructors should only allow cv qualifier adjustments, like Span<int> -> Span<const int>, not everything that is permitted by static_cast<pointer>(source.data()).

Thanks for landing the fix. I'd argue that it should be allowed since we are propagating the behavior of the pointer type

Hm, maybe the conversion could be made explicit for such cases, rather than disallowed entirely.

Hm, maybe the conversion could be made explicit for such cases, rather than disallowed entirely.

True true. That makes sense then.
Closing this issue as resolved.