STL
STL copied to clipboard
`<mdspan>`: `std::mdspan` should reject reference `ElementType`
Describe the bug
std::mdspan accepts a reference type as its ElementType.
Reproduction
#include <mdspan>
struct BadAccessor {
using offset_policy = BadAccessor;
using element_type = int&;
using reference = int&;
using data_handle_type = int*;
reference access(data_handle_type p, std::size_t i) const {
return p[i];
}
};
int main() {
std::mdspan<int&, std::dextents<int, 2>, std::layout_right, BadAccessor> m;
}
Expected behavior
According to [mdspan.mdspan.overview]
ElementType is a complete object type that is neither an abstract class type nor an array type,
The program should be rejected as ill-formed.
STL version
202508
Additional context
libstdc++ and libc++ also accept this. https://godbolt.org/z/PeP6beWWb
Confirmed. This wording has been present since the beginning, and https://github.com/microsoft/STL/blob/da06be8fa38418772506328177b703b28ca75699/stl/inc/mdspan#L1257-L1267 simply didn't enforce it.