Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bdce53

Browse files
committed
Add test for avoiding stack-overflow using tail calls.
1 parent f86130a commit 2bdce53

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/lazy_task_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,22 @@ TEST_CASE("chained fmap pipe operations")
350350
}();
351351
}
352352

353+
TEST_CASE("lazy_task resumption uses tail call to avoid stack overflow")
354+
{
355+
bool completedSynchronously = []() -> cppcoro::task<>
356+
{
357+
auto completesSynchronously = []() -> cppcoro::lazy_task<> { co_return; };
358+
359+
// Await a large number of synchronously-completing lazy_task values
360+
// in a row. If the lazy_task's final_suspend is not doing tail-calls
361+
// to resume the awaiter then this will blow the stack.
362+
for (int i = 0; i < 100000; ++i)
363+
{
364+
co_await completesSynchronously();
365+
}
366+
}().is_ready();
367+
368+
CHECK(completedSynchronously);
369+
}
370+
353371
TEST_SUITE_END();

0 commit comments

Comments
 (0)