From 1fcf550b956fae941b22bdf4a72dcdbd58d3fcf3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 Oct 2026 20:59:21 -1000 Subject: [PATCH] Hold the created test callback in a static like a setup-time registration --- tests/components/core/test_callback.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/components/core/test_callback.cpp b/tests/components/core/test_callback.cpp index c6ddf98d2f8..a0c004abef4 100644 --- a/tests/components/core/test_callback.cpp +++ b/tests/components/core/test_callback.cpp @@ -49,11 +49,11 @@ TEST(CallbackCreate, InlineCallableIsCalled) { int mutable_seen = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) // A pointer-sized mutable lambda used to be stored inline and run on a copy, losing its state. -// create() never frees its heap path by design; the host tests run with leak detection off. TEST(CallbackCreate, MutableStateIsKeptAcrossCalls) { auto counter = [n = 0](int x) mutable { mutable_seen = (n += x); }; static_assert(sizeof(counter) <= sizeof(void *) && std::is_trivially_copyable_v); - auto cb = IntCallback::create(counter); + // create() never frees its heap path; held for the whole run like a callback registered in setup(). + static const auto cb = IntCallback::create(counter); cb.call(1); cb.call(2); EXPECT_EQ(mutable_seen, 3);