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

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 25 09:54:29 PST 2022


ldionne added inline comments.


================
Comment at: libcxx/include/__iterator/common_iterator.h:34-36
+  requires { typename iter_value_t<_Iter>; } &&
+  constructible_from<iter_value_t<_Iter>, iter_reference_t<_Iter>> &&
+  move_constructible<iter_value_t<_Iter>>;
----------------
Quuxplusone wrote:
> Nit: Did you add line 34 to avoid prematurely instantiating `iter_reference_t`? Is it possible to regression-test for that? Should we? If removing line 34 would be conforming, I'd just do that.
No, the constraint was redundant with simply using `iter_value_t` in the expressions themselves. Removed.


================
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).
+  {
----------------
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.


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