From e87b8f6886f63935daf838c7a12a99417dd01691 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 23:13:18 -1000 Subject: [PATCH 1/2] Add add_ non-template trampoline to StaticCallbackManager --- esphome/core/helpers.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index d1477ca1e1c..f96b888e287 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1844,9 +1844,7 @@ template class StaticCallbackManager { public: /// Add any callable. Small trivially-copyable callables (like [this] lambdas) /// are stored inline without heap allocation. - template void add(F &&callback) { - this->callbacks_.push_back(Callback::create(std::forward(callback))); - } + template void add(F &&callback) { this->add_(Callback::create(std::forward(callback))); } /// Call all callbacks in this manager. void call(Ts... args) { @@ -1859,6 +1857,8 @@ template class StaticCallbackManager { void operator()(Ts... args) { call(args...); } protected: + /// Non-template core to avoid code duplication per lambda type. + void add_(Callback cb) { this->callbacks_.push_back(cb); } StaticVector, N> callbacks_; }; From 1441f4ebd7b13992839af9db772ab6a1d5774004 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 23:14:29 -1000 Subject: [PATCH 2/2] Clarify docstring for _add_callback --- esphome/components/esp32_ble/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/components/esp32_ble/__init__.py b/esphome/components/esp32_ble/__init__.py index 3a388116488..2e5e3587536 100644 --- a/esphome/components/esp32_ble/__init__.py +++ b/esphome/components/esp32_ble/__init__.py @@ -143,8 +143,9 @@ def _add_callback( ) -> None: """Generate a lambda callback that forwards to a handler method. - Uses a braced scope with a local variable to avoid capturing variables - with static storage duration. + Uses a braced scope with a local pointer variable so the generated C++ + lambda captures only that pointer, avoiding GCC warnings about capturing + variables with static storage duration. """ cg.add( cg.RawStatement(