Bug 117231 - [15 regression] Incorrect code generation for std::generator since r15-3840-g650e9156656187
Summary: [15 regression] Incorrect code generation for std::generator since r15-3840-g...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: 15.0
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-coroutines, wrong-code
Depends on:
Blocks:
 
Reported: 2024-10-19 20:16 UTC by Yihe Li
Modified: 2024-11-02 08:15 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-11-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yihe Li 2024-10-19 20:16:44 UTC
With GCC trunk, the following minimal usage of std::generator results in incorrect code:
```cpp
#include <generator>
#include <print>
#include <vector>

std::generator<int> get_seq()
{
    std::vector<int> data_{1, 2, 3};
    for (auto item : data_)
        co_yield item;
}

int main()
{
    for (auto item : get_seq())
        std::println("{}", item);
}
```
The expected result, and what is outputted by GCC 14.2, is "1 2 3" on three lines. However, with the GCC trunk, only a single 0 is outputted. See https://godbolt.org/z/fE1593c9h.
Comment 1 Patrick Palka 2024-10-21 12:35:05 UTC
Seems to have started with r15-3840-g650e9156656187.