[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 gcc-bugzilla@gcc.gnu.org
Fri May 8 23:50:12 GMT 2020


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);
    }
}
---------------------


More information about the Gcc-bugs mailing list