Sat, 22 Jan 2022 19:10:04 +0100
pointer type must be explicit in cx_foreach macro
src/cx/iterator.h | file | annotate | diff | comparison | revisions | |
test/test_list.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/cx/iterator.h Sat Jan 22 19:04:32 2022 +0100 1.2 +++ b/src/cx/iterator.h Sat Jan 22 19:10:04 2022 +0100 1.3 @@ -138,6 +138,6 @@ 1.4 * @param iter the iterator 1.5 */ 1.6 #define cx_foreach(type, elem, iter) \ 1.7 -for (type *elem; cxIteratorValid(&iter) && (elem = cxIteratorCurrent(&iter)) != NULL ; cxIteratorNext(&iter)) // NOLINT(bugprone-macro-parentheses) 1.8 +for (type elem; cxIteratorValid(&iter) && (elem = cxIteratorCurrent(&iter)) != NULL ; cxIteratorNext(&iter)) // NOLINT(bugprone-macro-parentheses) 1.9 1.10 #endif /* UCX_ITERATOR_H */
2.1 --- a/test/test_list.c Sat Jan 22 19:04:32 2022 +0100 2.2 +++ b/test/test_list.c Sat Jan 22 19:10:04 2022 +0100 2.3 @@ -762,10 +762,10 @@ 2.4 void test_hl_linked_list_iterator_impl(CxList list) { 2.5 int i = 0; 2.6 CxIterator iter = cxListBegin(list); 2.7 - cx_foreach(int, x, iter) { 2.8 + cx_foreach(int*, x, iter) { 2.9 CU_ASSERT_EQUAL(iter.index, (size_t) (i + 1) / 2) 2.10 CU_ASSERT_EQUAL(*x, i) 2.11 - if (i % 2 == 1) iter.remove = true; 2.12 + if (*x % 2 == 1) iter.remove = true; 2.13 i++; 2.14 } 2.15 CU_ASSERT_EQUAL(i, 10)