[libcxx-commits] [libcxx] [libc++][ranges][enumerate_view] Fix iterator converting constructor test (PR #212044)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 7 09:21:25 PDT 2026
lknknm wrote:
@Zingam Please check. I removed one of the tests and refactored it a little bit.
I think all the tests are now fulfilling the `iterator` converting ctor. As I said before, I ported 2 test cases from `zip_view` and left just one previous test case because it tests the condition `iterator(iterator<!Const> i)`
I tried the muting/changing a few things in the implementation temporarily and retesting every time, so I could see if the proposed tests were actually triggered and fail.
>From the original impl:
```cpp
_LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator<!_Const> __i)
requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
: __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
```
I changed to test:
| # | Change | Test Case: |
| -------- | -------- | -------- |
| 1 | `requires __Const && convertible_to<...> && false` | `TestIt`: `static_assert(convertible_to<EnumerateIterator, EnumerateConstIterator>` |
| 2 | `__pos_(__i.__pos_)` to `pos_(i.pos_ + 5)` | `assert(index == 1)` in `TestIt` for a `++it` check |
| 3 | `explicit constexpr iterator(iterator<!Const> i)` | `iter2 = iter1` for copy-init in NonSimpleCommon block (compile error) |
| 4 | `requires convertible_to<iterator_t<V>, iterator_t<Base>>` (remove the `__Const`) | `static_assert(!constructible_from<decltype(iter1), decltype(iter2)>)` for `NonSimpleCommon` (L94) |
| 5 | `requires __Const` (remove the `convertible_to<...>`) | Both `constructible_from` asserts in `ConstIterIncompatibleView` block |
I hope this can now cover all scenarios. I think the test is a bit more complete now and less redundant.
Please let me know :)
https://github.com/llvm/llvm-project/pull/212044
More information about the libcxx-commits
mailing list