https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102482

--- Comment #4 from Federico Kircheis <federico.kircheis at gmail dot com> ---
Note that following equivalent snippet

----
#include <initializer_list>

struct span {
    span(std::initializer_list<int> il) noexcept : begin(nullptr),
size(il.size()) { begin = il.begin();}
    const int* begin;
    std::size_t size;
};
----

does not trigger the warning.

> And the fabulous manual [...]

Mhm, I should have done a little more research before opening this ticket.

> *   When a list constructor stores the "begin" pointer from the
>     "initializer_list" argument, this doesn't extend the lifetime of
>     the array, so if a class variable is constructed from a temporary
>     "initializer_list", the pointer is left dangling by the end of the
>     variable declaration statement.

The first statement is correct (does not extend lifetime), but the second is
not always (the pointer is not always left dangling).


Also following snippet generates the warning:

----
#include <initializer_list>

struct span {
    span(std::initializer_list<int>& il) noexcept : begin(il.begin()),
size(il.size()) {}
    const int* begin;
    std::size_t size;
};
----

but I currently cannot imagine a scenario where this would dangle, as one
cannot write "span({1,2,3})"

Reply via email to