From 80cb914e064809e5440b8747a508547fc11c77de Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sat, 13 Apr 2024 17:23:25 +0200 Subject: [PATCH] [Core] Fix incorrect comparison for `Array` const iterator --- core/variant/array.h | 2 +- tests/core/variant/test_array.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/variant/array.h b/core/variant/array.h index d45a6887e25..3aa957b3126 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -54,7 +54,7 @@ public: _FORCE_INLINE_ ConstIterator &operator--(); _FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; } - _FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr != p_other.element_ptr; } _FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr, Variant *p_read_only = nullptr) : element_ptr(p_element_ptr), read_only(p_read_only) {} diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h index 287345e8312..c54854e4d72 100644 --- a/tests/core/variant/test_array.h +++ b/tests/core/variant/test_array.h @@ -555,6 +555,8 @@ TEST_CASE("[Array] Iteration") { idx++; } + CHECK_EQ(idx, a1.size()); + idx = 0; for (const Variant &E : (const Array &)a1) { @@ -562,6 +564,8 @@ TEST_CASE("[Array] Iteration") { idx++; } + CHECK_EQ(idx, a1.size()); + a1.clear(); }