diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index 913e8fdb85b2..71edebdfd097 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -76,6 +76,16 @@ class _WARN_UNUSED_ LocalVector { } } + // Can't use `_resize(0)`, since it requires a no-arg-constructor even if it wouldn't be called. + void _clear() { + if constexpr (!std::is_trivially_destructible_v) { + for (U i = 0; i < count; i++) { + data[i].~T(); + } + } + count = 0; + } + public: _FORCE_INLINE_ T *ptr() _LIFETIME_BOUND_ { return data; } _FORCE_INLINE_ const T *ptr() const _LIFETIME_BOUND_ { return data; } @@ -174,7 +184,7 @@ class _WARN_UNUSED_ LocalVector { [[deprecated("Use reverse() instead")]] void invert() { reverse(); } #endif - _FORCE_INLINE_ void clear() { resize(0); } + _FORCE_INLINE_ void clear() { _clear(); } _FORCE_INLINE_ void reset() { clear(); if (data) {