[libcxx-commits] [PATCH] D117449: [libc++] Fix common_iterator for output_iterators

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 26 13:17:52 PST 2022


ldionne added a comment.

In D117449#3270076 <https://reviews.llvm.org/D117449#3270076>, @Quuxplusone wrote:

> I assume this is still OK, and still necessary, even after D117400 <https://reviews.llvm.org/D117400> which I assume must have merge-conflicted with it a lot?

Yes, still necessary. There were only small merge conflicts.



================
Comment at: libcxx/test/std/iterators/predef.iterators/iterators.common/plus_plus.pass.cpp:154-155
+
+  // Increment a common_iterator<output_iterator>: iter_value_t is not valid for output iterators,
+  // so this gets tricky when we define operator++(int).
+  {
----------------
Quuxplusone wrote:
> ldionne wrote:
> > CaseyCarter wrote:
> > > Quuxplusone wrote:
> > > > IIUC this comment is misleading. `iter_value_t` for an ordinary C++11 output iterator is just `ThatType::value_type`. It's only if the iterator doesn't define a `value_type`, or defines it as a non-object type, that `iter_value_t` might be ill-formed.
> > > > https://godbolt.org/z/1Ybjv7o9G
> > > > Our test iterator's `output_iterator<int*>::value_type` is `void`, so its `iter_value_t` is indeed ill-formed, but that's a special property of //our// `output_iterator`, not all output iterators in general.
> > > > 
> > > > I'd like to see test coverage for "output iterator with valid value_type" added to `iterator_traits.compile.pass.cpp` above, even if this means defining a little helper type a la the `OutIt` in my godbolt.
> > > "need not be valid for output iterators" would be fine here.
> > Agreed, the comment was wrong, I'll fix it. However:
> > 
> > > I'd like to see test coverage for "output iterator with valid `value_type`" added to `iterator_traits.compile.pass.cpp` above, even if this means defining a little helper type a la the `OutIt` in my godbolt.
> > 
> > The problem is that even though `iter_value_t<OutputIter>` *can* be non-`void`, `iter_value_t<common_iterator<OutputIter>>` will never be, because we are now properly constraining the `iterator_traits<common_iterator<...>>` specialization to only work on `input_iterator`s. So I can't add a test that checks that `iter_value_t<common_iterator<OutputIter>>` is going to be non-`void`.
> > 
> > Please LMK if you think I'm mistaken here.
> I haven't investigated so I assume you're not mistaken. Then it just sounds like my request shifts from test coverage for `common_iterator<OutputIterWithNonVoidValueType>::iterator_category`, to test coverage that `common_iterator<OutputIterWithNonVoidValueType>` is SFINAE-friendly ill-formed. I believe we have some prior art, shaped roughly like
> ```
> template<class T>
> concept HasCommonIterator = requires { typename std::ranges::common_iterator<T>; };
> static_assert(!HasCommonIterator<OutputIterWithNonVoidValueType>);
> ```
I'm not following. `common_iterator<OutputIterWithNonVoidValueType>` does work, it's only that you can't query its `iterator_traits`.

I added a test in `iterator_traits.compile.pass.cpp` which isn't the most useful (because it ends up basically testing the `iterator_traits` base template), but should clarify what I mean.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117449/new/

https://reviews.llvm.org/D117449



More information about the libcxx-commits mailing list