diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 298bb80569..61d2944acf 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -133,10 +133,12 @@ template class TemplatableValue { case VALUE: return this->value_; case STATIC_STRING: + // if constexpr required: code must compile for all T, but STATIC_STRING + // can only be set when T is std::string (enforced by constructor constraint) if constexpr (std::same_as) { - return std::string(this->static_str_); // Convert to string only when needed + return std::string(this->static_str_); } - [[fallthrough]]; + __builtin_unreachable(); case NONE: default: return T{};