Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create a std::span from a gsl::span anymore after implementing P1394r4 #1016

Closed
ldionne opened this issue Nov 23, 2021 · 2 comments · Fixed by #1035
Closed

Can't create a std::span from a gsl::span anymore after implementing P1394r4 #1016

ldionne opened this issue Nov 23, 2021 · 2 comments · Fixed by #1035

Comments

@ldionne
Copy link

ldionne commented Nov 23, 2021

Since P1394r4, std::span changed the following constructors:

template<class Container> constexpr span(Container&);
template<class Container> constexpr span(const Container&);

into the following constructor:

template <class R> constexpr span(R&&);

where R must be a std::contiguous_range. However, as it happens, gsl::span does not qualify as a contiguous_range because its iterators are not contiguous_iterators. As a result, the following code starts failing when a Standard Library implements the resolution of P1394r4:

cat <<EOF | clang++ -xc++ - -std=c++20 -fsyntax-only
#include <gsl/span>
#include <span>
gsl::span<int> gsl_span;
std::span<int> std_span = gsl_span;
EOF

Here is a reproducer on Godbolt: https://godbolt.org/z/c1b686vjh. This worked previously with libc++ before we implemented P1394r4.

I would suggest that gsl::span's iterators be made contiguous_iterators in C++20, which would improve its interoperability with standard library types.

Note that this issue was found while building a large code base with the latest version of libc++ -- I suspect this issue is going to hit a decent number of people when LLVM 14 is released.

@dmitrykobets-msft
Copy link
Member

Hi @ldionne, thanks for finding this. Will investigate.

@dmitrykobets-msft
Copy link
Member

Related to #982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants