https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103912
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This happens because of:
/* Preserve a functions function context node. It will
later be needed to output debug info. */
if (tree fn = decl_function_context (decl))
{
cgraph_node *origin_node = cgraph_node::get_create (fn);
enqueue_node (origin_node);
}
in cgraphunit.c, operator() of the lambda is needed, so it is enqueued and the
above forces gimplification of the consteval function too, which is a big no
no, such functions shouldn't exist.
The big question is what do we want to do for debug info in these cases.
When using instead:
struct A {A (); };
constexpr auto
foo ()
{
if (1)
;
return [] (A x) { };
}
void
bar (A x)
{
constinit static auto h = foo ();
h (x);
}
ipa.c discovers that foo isn't reachable even when it is needed (as function
context of the lambda) and throws away the body and in the debug info just
emits DW_TAG_subprogram etc. for foo, but only emits non-code related stuff for
it.