1212
`<mdspan>`: `std::mdspan` should reject reference `ElementType` · Issue #6250 · microsoft/STL · GitHub
Skip to content

<mdspan>: std::mdspan should reject reference ElementType #6250

@eiytoq

Description

@eiytoq

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!mdspanC++23 mdspan

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions