Open ciaranm opened 3 months ago
It looks like this is like a bug in the test:
std::vector<int> events;
auto makeGen = [&]() -> std::generator<int> {
events.push_back(1);
scope_guard f{[&] { events.push_back(2); }};
auto nested = [&]() -> std::generator<int> {
events.push_back(3);
scope_guard g{[&] { events.push_back(4); }};
co_yield 42;
}();
scope_guard h{[&] { events.push_back(5); }};
co_yield std::ranges::elements_of(std::move(nested));
};
{
auto gen = makeGen();
auto it = gen.begin();
CHECK(*it == 42);
CHECK((events == std::vector{1, 3}));
}
CHECK((events == std::vector{1, 3, 4, 5, 2}));
The use of an immediately-invoked-lambda-with-captures which returns a generator which is not immediately consumed is going to leave the coroutine with a dangling reference to the lambda object which could be causing the sanitizer failure/crash.
To fix this bug the test would need to be changed to:
std::vector<int> events;
auto makeGen = [](std::vector<int>& events) -> std::generator<int> {
events.push_back(1);
scope_guard f{[&] { events.push_back(2); }};
auto nested = [](std::vector<int>& events) -> std::generator<int> {
events.push_back(3);
scope_guard g{[&] { events.push_back(4); }};
co_yield 42;
}(events);
scope_guard h{[&] { events.push_back(5); }};
co_yield std::ranges::elements_of(std::move(nested));
};
{
auto gen = makeGen(events);
auto it = gen.begin();
CHECK(*it == 42);
CHECK((events == std::vector{1, 3}));
}
CHECK((events == std::vector{1, 3, 4, 5, 2}));
I have not yet tested this, however, so it's possible there may still be other issues. Please try this out and see if it fixes the problem.
I'm not clever enough to figure out whether this is a compiler problem, a library problem, or a tests problem, but nested_test isn't happy on any of GitHub's ubuntu-22.04 runner, g++ 13.2.0 on Ubuntu 24.04, or clang 15.0.0 on OS X 14.5. I get either segfaults, bad_alloc being thrown, or valgrind errors, depending upon the system.
On Ubuntu 24.04, the test runs, but:
On OS X with clang, this crashes with a bad_alloc:
This is reproducible under GitHub actions, see e.g. https://github.com/ciaranm/glasgow-constraint-solver/actions/runs/9374592559/job/25810964264?pr=54