From 0326b1e93a264fa1190047fba902ba285a032ff8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Apr 2026 14:40:32 -1000 Subject: [PATCH] [core] Restore = delete for stateful lambdas in TemplatableFn --- esphome/core/automation.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 355968b284..7a054f9899 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -54,6 +54,9 @@ template class TemplatableFn { std::invocable &&std::convertible_to, T> &&std::is_empty_v &&std::default_initializable : f_([](X... x) -> T { return static_cast(F{}(x...)); }) {} + // Reject stateful lambdas (non-empty, i.e. capturing) with a clear error + template TemplatableFn(F) requires std::invocable &&(!std::is_empty_v) = delete; + bool has_value() const { return this->f_ != nullptr; } T value(X... x) const { return this->f_ ? this->f_(x...) : T{}; }