diff --git a/esphome/components/uart/uart.h b/esphome/components/uart/uart.h index eda5b72ea8..d1c6773363 100644 --- a/esphome/components/uart/uart.h +++ b/esphome/components/uart/uart.h @@ -37,9 +37,10 @@ class UARTDevice { bool read_array(uint8_t *data, size_t len) { return this->parent_->read_array(data, len); } template optional> read_array() { // NOLINT - std::array res; - if (!this->read_array(res.data(), N)) { - return {}; + // One object returned on both paths; a separate empty optional trips GCC's -Wmaybe-uninitialized. + optional> res(std::in_place); + if (!this->read_array(res->data(), N)) { + res.reset(); } return res; }