Created on 2025-09-30.00:00:00 last changed 1 week ago
Proposed resolution:
This wording is relative to N5014.
In subclause [simd.loadstore] replace all occurrences of
R(first, last)
by
R(first, static_cast<size_t>(last - first))
Currently, `simd::unchecked_load`/`partial_load`/`unchecked_store`/`partial_store` constructs a `span` via `span(first, last)` when taking an iterator-sentinel pair `first` and `last`.
However, the construction may not be well-behaved or well-formed when the sentinel type can be implicitly converted to an integer type. Consider:struct I { using value_type = int; using difference_type = int; using iterator_category = std::contiguous_iterator_tag; // contiguous iterator operators // ... operator int() const; }; int main() { std::simd::unchecked_load(I{}, I{}); }
Above, `unchecked_load` invokes `unchecked_load(I first, S last)` and we attempt to construct `span` through `span(first, last)`. However, this is invalid because the constructor requires that the sentinel type should not be convertible to `size_t`, so we fall back into `span(first, n)` via implicitly converting `I` to `size_t`. Such behavior is subtle and likely unintended.
Now consider:struct I { using value_type = int; using difference_type = int; using iterator_category = std::contiguous_iterator_tag; // contiguous iterator operators // ... operator int() &&; }; int main() { std::simd::unchecked_load(I{}, I{}); }
We still attempt to construct the `span` by calling `span(first, last)`, which is invalid, but because the lvalue sentinel cannot be converted to `size_t`, the call of `span(first, n)` is also invalid. This makes the construction of the `span` ill-formed and leads to a hard error in the function body.
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-10-03 15:46:08 | admin | set | messages: + msg15106 |
2025-09-30 00:00:00 | admin | create |