mirror of
https://github.com/esphome/esphome.git
synced 2026-06-04 09:22:23 +08:00
[core] Fix DelayAction compile error with non-const reference args
The lambda in DelayAction::play_complex must be `mutable` so captured copies of non-const reference arguments (e.g. std::string& from the http_request on_response trigger) can bind to the non-const reference parameters of play_next_(const Ts&...). Without `mutable`, the captured members are const-qualified and cannot bind to `T&`. Regression from #14968 which replaced std::bind with a lambda. Fixes https://github.com/esphome/esphome/issues/15808
This commit is contained in:
@@ -205,7 +205,9 @@ template<typename... Ts> class DelayAction : public Action<Ts...>, public Compon
|
|||||||
} else {
|
} else {
|
||||||
// For delays with arguments, capture by value to preserve argument values
|
// For delays with arguments, capture by value to preserve argument values
|
||||||
// Arguments must be copied because original references may be invalid after delay
|
// Arguments must be copied because original references may be invalid after delay
|
||||||
auto f = [this, x...]() { this->play_next_(x...); };
|
// `mutable` is required so captured copies of non-const reference args (e.g. std::string&)
|
||||||
|
// are passed as non-const lvalues to play_next_(const Ts&...) where Ts may be `T&`
|
||||||
|
auto f = [this, x...]() mutable { this->play_next_(x...); };
|
||||||
App.scheduler.set_timer_common_(this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL,
|
App.scheduler.set_timer_common_(this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL,
|
||||||
nullptr, static_cast<uint32_t>(InternalSchedulerID::DELAY_ACTION),
|
nullptr, static_cast<uint32_t>(InternalSchedulerID::DELAY_ACTION),
|
||||||
this->delay_.value(x...), std::move(f),
|
this->delay_.value(x...), std::move(f),
|
||||||
|
|||||||
Reference in New Issue
Block a user