On Wed, 11 Dec 2024 at 21:18, Giuseppe D'Angelo
<giuseppe.dang...@kdab.com> wrote:
>
> On 11/12/2024 21:41, Jonathan Wakely wrote:
> > Hmm, the warning is useful if somebody does:
> >
> > std::span s({1,2,3});
> >
> > So I think we do want the warning, but maybe give it a special case so
> > it doesn't warn for an rvalue std::span.
>
> Do you have anything in mind to make this work?

It would need changes to the front end, but I think they'd be useful changes.

>
> Note that the above is akin to:
>
> std::vector<int> getVector();
> std::span<const int> sp = getVector();
>
>
> which is also similar to:
>
> std::string getString();
> std::string_view sv = getString();
>
>
> and none of these warn at the moment.

They should do though :-)

If C++ had ref-qualified constructors then we could constrain the
std::span(Range&&)& constructor to only work for borrowed_ranges but
allow the std::span(Range&&)&& constructor to work for any ranges. We
don't have that though.

Reply via email to