From cd5db8510b634e711096e6b6e9f16110158392a4 Mon Sep 17 00:00:00 2001 From: Dmitry Prokoptsev Date: Tue, 11 Jun 2024 18:57:35 -0400 Subject: [PATCH] Fix tests on gcc-13 & 14. Recent gcc versions are not getting any better handling multiple co_await's and object initialization: when tried to enable CI for more recent compiler versions (gcc-13 & gcc-14), I (again) stumbled upon a triggered assert in AwaitableStateChecker. Rewrite this as a series of statements to work around the bug. Also while I'm here, fix format strings used in tests. --- test/basic_test.cc | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/basic_test.cc b/test/basic_test.cc index 9d41398..8e9c99c 100644 --- a/test/basic_test.cc +++ b/test/basic_test.cc @@ -95,37 +95,36 @@ class TestEventLoop { auto await_early_cancel() noexcept { if constexpr (Cancellable) { - CORRAL_TRACE("sleep %p (%lld ms) early cancelling", this, - delay_.count()); + CORRAL_TRACE("sleep %p (%ld ms) early cancelling", this, + delayMS()); return std::true_type{}; } else { - CORRAL_TRACE("sleep %p (%lld ms) NOT early cancelling", this, - delay_.count()); + CORRAL_TRACE("sleep %p (%ld ms) NOT early cancelling", this, + delayMS()); return false; } } bool await_ready() const noexcept { return false; } void await_suspend(Handle h) { - CORRAL_TRACE(" ...on sleep %p (%lld ms)", this, delay_.count()); + CORRAL_TRACE(" ...on sleep %p (%ld ms)", this, delayMS()); suspended_ = true; parent_ = h; it_ = eventLoop_.events_.emplace(eventLoop_.now_ + delay_, [this] { - CORRAL_TRACE("sleep %p (%lld ms) resuming parent", this, - delay_.count()); + CORRAL_TRACE("sleep %p (%ld ms) resuming parent", this, + delayMS()); suspended_ = false; parent_.resume(); }); } auto await_cancel(Handle) noexcept { if constexpr (Cancellable) { - CORRAL_TRACE("sleep %p (%lld ms) cancelling", this, - delay_.count()); + CORRAL_TRACE("sleep %p (%ld ms) cancelling", this, delayMS()); eventLoop_.events_.erase(it_); suspended_ = false; return std::true_type{}; } else { - CORRAL_TRACE("sleep %p (%lld ms) NOT cancelling", this, - delay_.count()); + CORRAL_TRACE("sleep %p (%ld ms) NOT cancelling", this, + delayMS()); return false; } } @@ -142,6 +141,9 @@ class TestEventLoop { void await_introspect(auto& c) const noexcept { c.node("Sleep"); } + private: + long delayMS() const { return static_cast(delay_.count()); } + private: TestEventLoop& eventLoop_; milliseconds delay_; @@ -1831,11 +1833,10 @@ CORRAL_TEST_CASE("bounded-channel") { CATCH_CHECK(channel.full()); CATCH_CHECK(ranLast == false); - std::array, 3> values = { - co_await channel.receive(), - co_await channel.receive(), - co_await channel.receive(), - }; + std::array, 3> values; + values[0] = co_await channel.receive(); + values[1] = co_await channel.receive(); + values[2] = co_await channel.receive(); CATCH_CHECK(values == std::array, 3>{1, 2, 3}); co_await yield;