Godot Engine – Multi-platform 2D and 3D game engine
Fix `LocalVector<T>::clear` when `T` has no default constructor
HolonProduction777e8632ca5f
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.hindex 913e8fdb85b..71edebdfd09 100644--- a/core/templates/local_vector.h+++ b/core/templates/local_vector.h@@ -76,6 +76,16 @@ private:}}+ // 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<T>) {+ 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 @@ public:[[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) {