diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 2267208752..c2f4cace9a 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -417,7 +417,7 @@ template::max()> FixedRingBuffer() = default; ~FixedRingBuffer() { - if constexpr (std::is_trivial::value) { + if constexpr (std::is_trivially_copyable::value && std::is_trivially_default_constructible::value) { ::operator delete(this->data_); } else { delete[] this->data_; @@ -430,7 +430,7 @@ template::max()> /// Allocate capacity - can only be called once void init(index_type capacity) { - if constexpr (std::is_trivial::value) { + if constexpr (std::is_trivially_copyable::value && std::is_trivially_default_constructible::value) { // Raw allocation without initialization (elements are written before read) // NOLINTNEXTLINE(bugprone-sizeof-expression) this->data_ = static_cast(::operator new(capacity * sizeof(T)));