kokkos / mdspan

Reference implementation of mdspan targeting C++23
Other
413 stars 69 forks source link

Missing restriction on ElementType and AccessorPolicy​::​element_type being the same #330

Closed pauleonix closed 6 months ago

pauleonix commented 6 months ago

According to the standard draft, cppreference and common sense these need to be the same, but at least when using the single header version I can instantiate e.g. std::mdspan<float, std::dextents<int, 2>, std::layout_right, std::default_accessor<double>> or std::mdspan<float const, std::dextents<int, 2>, std::layout_right, std::default_accessor<float>> without a compiler error.

See https://godbolt.org/z/nx4YE91G3

mhoemmen commented 6 months ago

Thank you for reporting this! I agree that this is a bug. The two types need to be the same. mdspan's Mandates clause ([mdspan.mdspan.overview] 2.3) includes "is_same_v<ElementType, typename AccessorPolicy​::​element_type> is true." "Mandates" means "should be ill-formed if violated, e.g., by using a static_assert."

Would you consider submitting a PR with a fix?