diff --git a/esphome/core/automation.h b/esphome/core/automation.h index fbe7224b70..355968b284 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -47,8 +47,10 @@ template class TemplatableFn { // Convertible return type (e.g., int -> uint8_t) — casting trampoline. // Stateless lambdas are default-constructible in C++20, so F{} recreates the lambda inside // the trampoline without capturing. This compiles to the same code as a direct call + cast. + // Deprecated: codegen should use the correct output type to avoid the trampoline. template - TemplatableFn(F) requires(!std::convertible_to) && + [[deprecated("Lambda return type does not match TemplatableFn — use the correct type in " + "codegen")]] TemplatableFn(F) requires(!std::convertible_to) && std::invocable &&std::convertible_to, T> &&std::is_empty_v &&std::default_initializable : f_([](X... x) -> T { return static_cast(F{}(x...)); }) {}