Skip to content

Commit 3d2ed2e

Browse files
committed
tests: coroutines: restore "explicit this" tests
These tests were added in acba465 ("coroutines: advertise lambda-capture-by-value and test it") and then inadvertently removed in 81f2dc9 ("coroutine: reimplement generator with buffered variant"). Restore them.
1 parent 70c5a5a commit 3d2ed2e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/unit/coroutines_test.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,30 @@ SEASTAR_TEST_CASE(test_lambda_coroutine_in_continuation) {
784784
}));
785785
BOOST_REQUIRE_EQUAL(sin1, sin2);
786786
}
787+
788+
#ifdef __cpp_explicit_this_parameter
789+
790+
SEASTAR_TEST_CASE(test_lambda_value_capture_coroutine) {
791+
// Note: crashes without "this auto"
792+
auto f1 = [p = std::make_unique<int>(7)] (this auto) -> future<int> {
793+
co_await yield();
794+
co_return *p + 2;
795+
}();
796+
// f1 is not ready at this point (due to the yield). Verify that the capture
797+
// group was copied to the coroutine frame.
798+
auto n = co_await std::move(f1);
799+
BOOST_REQUIRE_EQUAL(n, 9);
800+
}
801+
802+
SEASTAR_TEST_CASE(test_lambda_value_capture_continuation) {
803+
// Note: crashes without "this auto"
804+
return yield().then([p = std::make_unique<int>(7)] (this auto) -> future<int> {
805+
co_await yield();
806+
co_return *p + 2;
807+
}).then([] (int n) {
808+
BOOST_REQUIRE_EQUAL(n, 9);
809+
});
810+
}
811+
812+
813+
#endif

0 commit comments

Comments
 (0)