diff --git a/src/test/core/Coroutine_test.cpp b/src/test/core/Coroutine_test.cpp index a0065ecf45..4c43a9821d 100644 --- a/src/test/core/Coroutine_test.cpp +++ b/src/test/core/Coroutine_test.cpp @@ -70,11 +70,13 @@ public: Gate g1, g2; std::shared_ptr c; - // Safe capture: the test blocks on the Gates until the coroutine - // completes, so the captured pointers outlive the coroutine. - // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) env.app().getJobQueue().postCoroTask( - JtClient, "CoroTest", [cp = &c, g1p = &g1, g2p = &g2](auto runner) -> CoroTask { + JtClient, + "CoroTest", + // Safe capture: the test blocks on the Gates until the coroutine + // completes, so the captured pointers outlive the coroutine. + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + [cp = &c, g1p = &g1, g2p = &g2](auto runner) -> CoroTask { *cp = runner; g1p->signal(); co_await runner->suspend(); @@ -102,11 +104,13 @@ public: })); Gate g; - // Safe capture: the test blocks on the Gate until the coroutine - // completes, so the captured pointer outlives the coroutine. - // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) env.app().getJobQueue().postCoroTask( - JtClient, "CoroTest", [gp = &g](auto runner) -> CoroTask { + JtClient, + "CoroTest", + // Safe capture: the test blocks on the Gate until the coroutine + // completes, so the captured pointer outlives the coroutine. + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + [gp = &g](auto runner) -> CoroTask { // Schedule a resume before suspending. The posted job // cannot actually call resume() until the current resume() // releases CoroTaskRunner::mutex_, which only happens after diff --git a/src/test/core/JobQueue_test.cpp b/src/test/core/JobQueue_test.cpp index 20ff285e56..baa0944b68 100644 --- a/src/test/core/JobQueue_test.cpp +++ b/src/test/core/JobQueue_test.cpp @@ -60,11 +60,13 @@ class JobQueue_test : public beast::unit_test::Suite { // Test repeated post()s until the coroutine completes. std::atomic yieldCount{0}; - // Safe capture: the test blocks below until the coroutine - // completes, so the captured pointer outlives the coroutine. - // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) auto const runner = jQueue.postCoroTask( - JtClient, "PostCoroTest1", [ycp = &yieldCount](auto runner) -> CoroTask { + JtClient, + "PostCoroTest1", + // Safe capture: the test blocks below until the coroutine + // completes, so the captured pointer outlives the coroutine. + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + [ycp = &yieldCount](auto runner) -> CoroTask { while (++(*ycp) < 4) co_await runner->suspend(); co_return; @@ -91,11 +93,13 @@ class JobQueue_test : public beast::unit_test::Suite { // Test repeated post()+join()s until the coroutine completes. int yieldCount{0}; - // Safe capture: the test blocks below until the coroutine - // completes, so the captured pointer outlives the coroutine. - // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) auto const runner = jQueue.postCoroTask( - JtClient, "PostCoroTest2", [ycp = &yieldCount](auto runner) -> CoroTask { + JtClient, + "PostCoroTest2", + // Safe capture: the test blocks below until the coroutine + // completes, so the captured pointer outlives the coroutine. + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + [ycp = &yieldCount](auto runner) -> CoroTask { while (++(*ycp) < 4) co_await runner->suspend(); co_return; @@ -138,11 +142,13 @@ class JobQueue_test : public beast::unit_test::Suite // unprotected variable on the stack should be completely safe. // Not recommended for the faint of heart... bool unprotected = false; - // Safe capture: the JobQueue is stopped, so the coroutine is - // never started and the captured pointer is never dereferenced. - // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) auto const runner = jQueue.postCoroTask( - JtClient, "PostCoroTest3", [up = &unprotected](auto) -> CoroTask { + JtClient, + "PostCoroTest3", + // Safe capture: the JobQueue is stopped, so the coroutine is + // never started and the captured pointer is never dereferenced. + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + [up = &unprotected](auto) -> CoroTask { *up = true; co_return; });