diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 99c8b5f228..52188b2621 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef USE_ESP32 #if (ESP_IDF_VERSION_MAJOR >= 5 && ESP_IDF_VERSION_MINOR >= 1) diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index f0ccc95abe..7ae8a2c18a 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -10,6 +10,7 @@ #include #include +#include #include #ifdef USE_LIBRETINY @@ -219,12 +220,14 @@ class CompactString { }; static_assert(sizeof(CompactString) == 20, "CompactString must be exactly 20 bytes"); -// CompactString is safe to memcpy for permutation-based sorting (no ownership duplication). -// Unlike libstdc++ std::string which uses a self-referential pointer (_M_p -> _M_local_buf) -// in SSO mode, CompactString stores either inline data or an external heap pointer in -// storage_[] — never a pointer to itself. These asserts guard that property. -static_assert(std::is_standard_layout::value, "CompactString must be standard layout for memcpy safety"); -static_assert(!std::is_polymorphic::value, "CompactString must not have vtable for memcpy safety"); +// CompactString is not trivially copyable (non-trivial destructor/copy for heap case). +// However, its layout has no self-referential pointers: storage_[] contains either inline +// data or an external heap pointer — never a pointer to itself. This is unlike libstdc++ +// std::string SSO where _M_p points to _M_local_buf within the same object. +// This property allows memcpy-based permutation sorting where each element ends up in +// exactly one slot (no ownership duplication). These asserts document that layout property. +static_assert(std::is_standard_layout::value, "CompactString must be standard layout"); +static_assert(!std::is_polymorphic::value, "CompactString must not have vtable"); class WiFiAP { friend class WiFiComponent;