[Bug c++/102482] Winit-list-lifetime false positive for temporaries with std::initializer_list
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Sep 26 11:08:00 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102482
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Federico Kircheis from comment #0)
> While the warning is true, the code is completely safe, but the warnings
> seems to imply that foo will access a dangling pointer.
In this case it's safe because the span obejct has the same lifetime as the
initializer_list, but in general that's not true. The warning comes from the
constructor, and is independent of the context in which it's being constructed.
> so I assume the warning is std::initializer_list specific.
Yes. std::initializer_list is a magic language type that the compiler knows all
about. std::vector is just opaque C++ code that the compiler knows nothing
about.
More information about the Gcc-bugs
mailing list