public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95017] New: [coroutines] Failure to generate code for co_yield expression if its the only statement in a loop
@ 2020-05-08 23:50 lewissbaker.opensource at gmail dot com
  2020-05-08 23:51 ` [Bug c++/95017] " lewissbaker.opensource at gmail dot com
  2020-05-09 10:43 ` iains at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: lewissbaker.opensource at gmail dot com @ 2020-05-08 23:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95017
           Summary: [coroutines] Failure to generate code for co_yield
                    expression if its the only statement in a loop
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lewissbaker.opensource at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/v-Tkvi

Given a simple coroutine generator<T> type, if I compile the following
coroutine with GCC it fails to generate code for the 'co_yield' expression if
the co_yield is the only statement in the loop body.

However, if I add another statement after the co_yield then it correctly
generates code for the co_yield expression.

Works: -std=c++2a -fcoroutines -DWITH_EXTRA_STATEMENT
Fails: -std=c++2a -fcoroutines 

---------------------
generator<double> test()
{
    double i = 0;
    while(i++ < 5) {
        // If the second statement below is compiled-out then GCC fails to
generate
        // code for the co_yield expression and the loop completes without
        // ever suspending.
        co_yield i * 2;

#ifdef WITH_EXTRA_STATEMENT
        (void)i;
#endif
    }
}

int main() {
    for (auto i : test()) {
        printf("%f\t", i);
    }
}
---------------------

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

* [Bug c++/95017] [coroutines] Failure to generate code for co_yield expression if its the only statement in a loop
  2020-05-08 23:50 [Bug c++/95017] New: [coroutines] Failure to generate code for co_yield expression if its the only statement in a loop lewissbaker.opensource at gmail dot com
@ 2020-05-08 23:51 ` lewissbaker.opensource at gmail dot com
  2020-05-09 10:43 ` iains at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: lewissbaker.opensource at gmail dot com @ 2020-05-08 23:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Lewis Baker <lewissbaker.opensource at gmail dot com> ---
Created attachment 48487
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48487&action=edit
test.cpp

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

* [Bug c++/95017] [coroutines] Failure to generate code for co_yield expression if its the only statement in a loop
  2020-05-08 23:50 [Bug c++/95017] New: [coroutines] Failure to generate code for co_yield expression if its the only statement in a loop lewissbaker.opensource at gmail dot com
  2020-05-08 23:51 ` [Bug c++/95017] " lewissbaker.opensource at gmail dot com
@ 2020-05-09 10:43 ` iains at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: iains at gcc dot gnu.org @ 2020-05-09 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

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

--- Comment #2 from Iain Sandoe <iains at gcc dot gnu.org> ---
thanks for the report!
(an odd case where it's a single line loop which triggers the
reference-capture-lifetime-extension).

As luck would have it, this was fixed on master yesterday - and I will be back
porting the change to 10.2.

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

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

end of thread, other threads:[~2020-05-09 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 23:50 [Bug c++/95017] New: [coroutines] Failure to generate code for co_yield expression if its the only statement in a loop lewissbaker.opensource at gmail dot com
2020-05-08 23:51 ` [Bug c++/95017] " lewissbaker.opensource at gmail dot com
2020-05-09 10:43 ` iains 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).