Skip to content

undefined behavior in cti::when_all #76

Description

@Spongman

v4.2.2

#include <iostream>
#include <boost/asio.hpp>
#include <continuable/continuable.hpp>

template <typename T>
auto through_post(T& ctx) {
	return [&ctx](auto&& work) mutable {
		boost::asio::post(ctx, std::forward<decltype(work)>(work));
	};
};

int main() {
	boost::asio::io_context ctx;
	auto workGuard = boost::asio::make_work_guard(ctx);

	std::thread thread{[&ctx]() {
		while(!ctx.stopped()) {
			ctx.run();
		}
	}};

	std::vector<cti::continuable<bool>> tasks;
	tasks.push_back(cti::async_on(
		[]() -> cti::continuable<bool> {
			co_return true;
		},
		through_post(ctx)
	).finish());

	auto testsPassed = cti::when_all(tasks.begin(), tasks.end()).apply(cti::transforms::wait());
	std::cout << (testsPassed[0] ? "true" : "false") << "\n";

	workGuard.reset();
	ctx.stop();
	thread.join();
}
$ g++ --version
g++ (GCC) 13.3.1 20240611 (Red Hat 13.3.1-2)

$ g++ -std=c++20 -fsanitize=undefined test.cpp

$ ./a.out
continuable/detail/connection/connection-aggregated.hpp:105:7: runtime error: load of value 208, which is not a valid value for type 'bool'
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions