https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103543
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Summary|Potential compiler warning |Potential compiler warning
|for return of temporary? |for return of temporary
| |with std::function<const
| |T&()> converting from
| |T(*)()
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
That is because the lambda itself returns a S and not a const reference.
You do get a warning with -Wsystem-headers inside invoke.
With:
[]() -> S const& { return S{}; };
You do get the correct warning.
Also this has nothing to do with lambdas really but really std::function as
shown by:
struct S
{
int s{};
};
using F = std::function<S const& ()>;
auto fn()
{
return S{};
}
int main()
{
F f = fn; // No warning
__builtin_printf("%d.\n", f().s);
}
---- CUT ----
The above code is the same as the lambda case really.