https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107556
Bug ID: 107556 Summary: Passing lambda to a coroutine function triggers -Wsubobject-linkage Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dennis-hezel at gmx dot de Target Milestone: --- Affects GCC 10+ If you think the warning is legitimate then please advise how to change the code. Smallest reproducer I could come up with: https://godbolt.org/z/WvPE1qx8s It is not limited to `co_yield`, `co_await`-compatible coroutines also trigger it. Reproducer here incase the compiler explorer link does not work: other.hpp ```c++ #include <coroutine> struct Generator { struct promise_type { Generator get_return_object() { return Generator{}; } std::suspend_always initial_suspend() { return {}; } std::suspend_always final_suspend() noexcept { return {}; } std::suspend_always yield_value(int) { return {}; } void unhandled_exception() {} }; }; template <class F> auto invoke_and_await(F) -> Generator { co_yield 1; } auto test() { invoke_and_await([] {}); } ``` main.cpp ```c++ // must be included, copy-pasting the code into here won't trigger it #include "other.hpp" ``` Compiler output: ``` In file included from /app/main.cpp:2: other.hpp: In instantiation of 'Generator invoke_and_await(F) [with F = test()::<lambda()>]': other.hpp:23:27: required from here other.hpp:19:1: warning: 'invoke_and_await<test()::<lambda()> >::_Z16invoke_and_awaitIZ4testvEUlvE_E9GeneratorT_.frame' has a field 'invoke_and_await<test()::<lambda()> >::_Z16invoke_and_awaitIZ4testvEUlvE_E9GeneratorT_.frame::__unnamed_parm.0' whose type has no linkage [-Wsubobject-linkage] 19 | } | ^ ``` Compile with `-fcoroutines` before GCC version 11.