On Tue, 3 Dec 2024 at 16:07, Giuseppe D'Angelo
<giuseppe.dang...@kdab.com> wrote:
>
> Hello,
>
> The attached patch adds the span(initializer_list) constructor, added by
> P2447R6 for C++26.
>
> It seems that GCC is somewhat aggressive with its -Winit-list-lifetime
> warning, which actively interferes with this feature. The idea of the
> new constructor is to allow calls like:
>
>    void f(std::span<const int>);
>    f({1, 2, 3});
>
> which is completely fine as the lifetime of the initializer_list
> encompasses the one of the std::span parameter. However GCC complains
> about the risk of dangling here. I've therefore disabled the warning for
> the new constructor.

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.

Alternatively, we'd want that constructor to be marked with the
opposite of [[nodiscard]], saying to warn if it *isn't* discarded!

Reply via email to