From 7385004952651451b45fc53a003f8e5da7fdd6f0 Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Mon, 27 Jul 2026 13:06:13 +0100 Subject: [PATCH] Move coroutine-capture NOLINTNEXTLINE comments next to the lambdas clang-format placed the suppression comments two lines above the lambda expressions (before the postCoroTask call), so NOLINTNEXTLINE suppressed the wrong line and clang-tidy still reported cppcoreguidelines-avoid-capturing-lambda-coroutines at the lambda. Move the comments inside the argument list, immediately before each lambda, matching the pattern already used in threadSpecificStorage. --- src/test/core/Coroutine_test.cpp | 20 ++++++++++++-------- src/test/core/JobQueue_test.cpp | 30 ++++++++++++++++++------------ 2 files changed, 30 insertions(+), 20 deletions(-) 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; });