public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107556] New: Passing lambda to a coroutine function triggers -Wsubobject-linkage
@ 2022-11-07 13:41 dennis-hezel at gmx dot de
  2022-11-07 16:53 ` [Bug c++/107556] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: dennis-hezel at gmx dot de @ 2022-11-07 13:41 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/107556] Passing lambda to a coroutine function triggers -Wsubobject-linkage
  2022-11-07 13:41 [Bug c++/107556] New: Passing lambda to a coroutine function triggers -Wsubobject-linkage dennis-hezel at gmx dot de
@ 2022-11-07 16:53 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-07 16:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 105595.

*** This bug has been marked as a duplicate of bug 105595 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-07 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 13:41 [Bug c++/107556] New: Passing lambda to a coroutine function triggers -Wsubobject-linkage dennis-hezel at gmx dot de
2022-11-07 16:53 ` [Bug c++/107556] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).