Skip to content

Commit 578d937

Browse files
authored
Merge pull request godotengine#90631 from AThousandShips/array_iter_fix
[Core] Fix incorrect comparison for `Array` const iterator
2 parents 43b32f9 + 80cb914 commit 578d937

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

core/variant/array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Array {
5454
_FORCE_INLINE_ ConstIterator &operator--();
5555

5656
_FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; }
57-
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; }
57+
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr != p_other.element_ptr; }
5858

5959
_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr, Variant *p_read_only = nullptr) :
6060
element_ptr(p_element_ptr), read_only(p_read_only) {}

tests/core/variant/test_array.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,17 @@ TEST_CASE("[Array] Iteration") {
555555
idx++;
556556
}
557557

558+
CHECK_EQ(idx, a1.size());
559+
558560
idx = 0;
559561

560562
for (const Variant &E : (const Array &)a1) {
561563
CHECK_EQ(int(a2[idx]), int(E));
562564
idx++;
563565
}
564566

567+
CHECK_EQ(idx, a1.size());
568+
565569
a1.clear();
566570
}
567571

0 commit comments

Comments
 (0)