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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Dimitry Andric from comment #0)
> Clearly, there is no dangling reference here, and not even a temporary. And
> even if there was a temporary, its lifetime should have been extended.

No, the temporary it's talking about is the by-value match_t parameter, which
is created when initializing the find parameter. That would not have its
lifetime extended.

The reason there's a warning here is that match_t does contain a std::string,
so the compiler conservatively assumes that the returned const std::string&
refers to the name+ member of the function parameter. If that were the case, it
would indeed be a dangling reference.

You can use [[gnu::no_dangling]] on the fund function template to tell GCC that
it never dangles (although that's not quite true, because find({""}, match)
could dangle).

Reply via email to