d: Fix undefined reference to nested lambda in template (PR108055)
authorIain Buclaw <ibuclaw@gdcproject.org>
Sat, 10 Dec 2022 21:11:41 +0000 (22:11 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 12 Dec 2022 19:10:25 +0000 (20:10 +0100)
commit9fe7d3debbf60ed9fef8053123ad542a99d62100
tree1d955d496d79e4daa1b37bb1d6a89f6592a14681
parent2d7c73ee5eae47eee16ddab3df2928ff5a7dd89c
d: Fix undefined reference to nested lambda in template (PR108055)

Sometimes, nested lambdas of templated functions get no code generation
due to them being marked as instantianted outside of all modules being
compiled in the current compilation unit.  This despite enclosing
template instances being marked as instantiated inside the current
compilation unit.  To fix, all enclosing templates are now checked in
`function_defined_in_root_p'.

Because of this change, `function_needs_inline_definition_p' has also
been fixed up to only check whether the regular function definition
itself is to be emitted in the current compilation unit.

PR d/108055

gcc/d/ChangeLog:

* decl.cc (function_defined_in_root_p): Check all enclosing template
instances for definition in a root module.
(function_needs_inline_definition_p): Replace call to
function_defined_in_root_p with test for outer module `isRoot'.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/imports/pr108055conv.d: New.
* gdc.dg/torture/imports/pr108055spec.d: New.
* gdc.dg/torture/imports/pr108055write.d: New.
* gdc.dg/torture/pr108055.d: New test.
gcc/d/decl.cc
gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/torture/imports/pr108055write.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/torture/pr108055.d [new file with mode: 0644]