[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-06-10 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

Patrick Palka  changed:

   What|Removed |Added

 Resolution|--- |FIXED
   Target Milestone|--- |10.4
 Status|ASSIGNED|RESOLVED

--- Comment #14 from Patrick Palka  ---
Fixed for 10.4/11.2/12

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-06-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #13 from CVS Commits  ---
The releases/gcc-10 branch has been updated by Patrick Palka
:

https://gcc.gnu.org/g:b1f54b2b7d876c72ab05afb0df214aba205f94ad

commit r10-9904-gb1f54b2b7d876c72ab05afb0df214aba205f94ad
Author: Patrick Palka 
Date:   Tue May 18 10:21:27 2021 -0400

libstdc++: Fix access issue in elements_view::_Sentinel [PR100631]

In the earlier commit r12-854 I forgot to also rewrite the other operator-
overload in terms of the split-out member function _M_distance_from.

libstdc++-v3/ChangeLog:

PR libstdc++/100631
* include/std/ranges (elements_view::_Sentinel::operator-): Use
_M_distance_from in the other operator- overload too.
* testsuite/std/ranges/adaptors/elements.cc (test06): Augment test.

(cherry picked from commit 38751c4d5e15bd1c682ac4c868a2c4ce48ca5503)

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-06-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #12 from CVS Commits  ---
The releases/gcc-10 branch has been updated by Patrick Palka
:

https://gcc.gnu.org/g:648c786bc6451115604c60abcc7977b3c6987ae4

commit r10-9903-g648c786bc6451115604c60abcc7977b3c6987ae4
Author: Patrick Palka 
Date:   Tue May 18 00:26:07 2021 -0400

libstdc++: Fix miscellaneous issues with elements_view::_Sentinel
[PR100631]

libstdc++-v3/ChangeLog:

PR libstdc++/100631
* include/std/ranges (elements_view::_Iterator): Also befriend
_Sentinel.
(elements_view::_Sentinel::_M_equal): Templatize.
(elements_view::_Sentinel::_M_distance_from): Split out from ...
(elements_view::_Sentinel::operator-): ... here.  Depend on
_Base2 instead of _Base in the return type.
* testsuite/std/ranges/adaptors/elements.cc (test06, test07):
New tests.

(cherry picked from commit 2e2eef80ac0c21f9533e6791ccf5e29458cbb77c)

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-06-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #11 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Patrick Palka
:

https://gcc.gnu.org/g:3b93d61be5a5a93e95783b80c58b297e215badf1

commit r11-8542-g3b93d61be5a5a93e95783b80c58b297e215badf1
Author: Patrick Palka 
Date:   Tue May 18 10:21:27 2021 -0400

libstdc++: Fix access issue in elements_view::_Sentinel [PR100631]

In the earlier commit r12-854 I forgot to also rewrite the other operator-
overload in terms of the split-out member function _M_distance_from.

libstdc++-v3/ChangeLog:

PR libstdc++/100631
* include/std/ranges (elements_view::_Sentinel::operator-): Use
_M_distance_from in the other operator- overload too.
* testsuite/std/ranges/adaptors/elements.cc (test06): Augment test.

(cherry picked from commit 38751c4d5e15bd1c682ac4c868a2c4ce48ca5503)

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-06-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #10 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Patrick Palka
:

https://gcc.gnu.org/g:fd4db3ddc3639e03f557010b8e0e947e4b51633e

commit r11-8541-gfd4db3ddc3639e03f557010b8e0e947e4b51633e
Author: Patrick Palka 
Date:   Tue May 18 00:26:07 2021 -0400

libstdc++: Fix miscellaneous issues with elements_view::_Sentinel
[PR100631]

libstdc++-v3/ChangeLog:

PR libstdc++/100631
* include/std/ranges (elements_view::_Iterator): Also befriend
_Sentinel.
(elements_view::_Sentinel::_M_equal): Templatize.
(elements_view::_Sentinel::_M_distance_from): Split out from ...
(elements_view::_Sentinel::operator-): ... here.  Depend on
_Base2 instead of _Base in the return type.
* testsuite/std/ranges/adaptors/elements.cc (test06, test07):
New tests.

(cherry picked from commit 2e2eef80ac0c21f9533e6791ccf5e29458cbb77c)

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-18 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #9 from CVS Commits  ---
The master branch has been updated by Patrick Palka :

https://gcc.gnu.org/g:38751c4d5e15bd1c682ac4c868a2c4ce48ca5503

commit r12-880-g38751c4d5e15bd1c682ac4c868a2c4ce48ca5503
Author: Patrick Palka 
Date:   Tue May 18 10:21:27 2021 -0400

libstdc++: Fix access issue in elements_view::_Sentinel [PR100631]

In the earlier commit r12-854 I forgot to also rewrite the other operator-
overload in terms of the split-out member function _M_distance_from.

libstdc++-v3/ChangeLog:

PR libstdc++/100631
* include/std/ranges (elements_view::_Sentinel::operator-): Use
_M_distance_from in the other operator- overload too.
* testsuite/std/ranges/adaptors/elements.cc (test06): Augment test.

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-18 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #8 from Patrick Palka  ---
(In reply to 康桓瑋 from comment #7)
> (In reply to CVS Commits from comment #6)
> > The master branch has been updated by Patrick Palka :
> > 
> > https://gcc.gnu.org/g:2e2eef80ac0c21f9533e6791ccf5e29458cbb77c
> > 
> > commit r12-854-g2e2eef80ac0c21f9533e6791ccf5e29458cbb77c
> > Author: Patrick Palka 
> > Date:   Tue May 18 00:26:07 2021 -0400
> > 
> > libstdc++: Fix miscellaneous issues with elements_view::_Sentinel
> > [PR100631]
> > 
> > libstdc++-v3/ChangeLog:
> > 
> > PR libstdc++/100631
> > * include/std/ranges (elements_view::_Iterator): Also befriend
> > _Sentinel.
> > (elements_view::_Sentinel::_M_equal): Templatize.
> > (elements_view::_Sentinel::_M_distance_from): Split out from ...
> > (elements_view::_Sentinel::operator-): ... here.  Depend on
> > _Base2 instead of _Base in the return type.
> > * testsuite/std/ranges/adaptors/elements.cc (test06, test07):
> > New tests.
> 
> 
> 
> Hey, Patrick, you missed the second one:
> 
> 
> template  typename _Base2 = __detail::__maybe_const_t<_Const2, _Vp>>
> requires sized_sentinel_for, iterator_t<_Base2>>
> friend constexpr range_difference_t<_Base2>
> operator-(const _Iterator<_Const2>& __x, const _Sentinel& __y)
> { return __x._M_current - __y._M_end; }
> 
> 
> this should be return -__y._M_distance_from(__x).

Indeed, thanks for catching that.  Fix incoming shortly..

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-17 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #7 from 康桓瑋  ---
(In reply to CVS Commits from comment #6)
> The master branch has been updated by Patrick Palka :
> 
> https://gcc.gnu.org/g:2e2eef80ac0c21f9533e6791ccf5e29458cbb77c
> 
> commit r12-854-g2e2eef80ac0c21f9533e6791ccf5e29458cbb77c
> Author: Patrick Palka 
> Date:   Tue May 18 00:26:07 2021 -0400
> 
> libstdc++: Fix miscellaneous issues with elements_view::_Sentinel
> [PR100631]
> 
> libstdc++-v3/ChangeLog:
> 
> PR libstdc++/100631
> * include/std/ranges (elements_view::_Iterator): Also befriend
> _Sentinel.
> (elements_view::_Sentinel::_M_equal): Templatize.
> (elements_view::_Sentinel::_M_distance_from): Split out from ...
> (elements_view::_Sentinel::operator-): ... here.  Depend on
> _Base2 instead of _Base in the return type.
> * testsuite/std/ranges/adaptors/elements.cc (test06, test07):
> New tests.



Hey, Patrick, you missed the second one:


template>
requires sized_sentinel_for, iterator_t<_Base2>>
friend constexpr range_difference_t<_Base2>
operator-(const _Iterator<_Const2>& __x, const _Sentinel& __y)
{ return __x._M_current - __y._M_end; }


this should be return -__y._M_distance_from(__x).

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-17 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Patrick Palka :

https://gcc.gnu.org/g:2e2eef80ac0c21f9533e6791ccf5e29458cbb77c

commit r12-854-g2e2eef80ac0c21f9533e6791ccf5e29458cbb77c
Author: Patrick Palka 
Date:   Tue May 18 00:26:07 2021 -0400

libstdc++: Fix miscellaneous issues with elements_view::_Sentinel
[PR100631]

libstdc++-v3/ChangeLog:

PR libstdc++/100631
* include/std/ranges (elements_view::_Iterator): Also befriend
_Sentinel.
(elements_view::_Sentinel::_M_equal): Templatize.
(elements_view::_Sentinel::_M_distance_from): Split out from ...
(elements_view::_Sentinel::operator-): ... here.  Depend on
_Base2 instead of _Base in the return type.
* testsuite/std/ranges/adaptors/elements.cc (test06, test07):
New tests.

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-17 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #5 from 康桓瑋  ---
(In reply to TC from comment #4)

> This one is a problem with the WP.

Thanks, Tim, does it have an LWG number?

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-17 Thread rs2740 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

TC  changed:

   What|Removed |Added

 CC||rs2740 at gmail dot com

--- Comment #4 from TC  ---
(In reply to 康桓瑋 from comment #1)
> Another issue is that in elements_view::_Sentinel in ranges#L3677:
> 
> 
>   templatetypename _Base2 = __detail::__maybe_const_t<_Const2, _Vp>>
> requires sized_sentinel_for, iterator_t<_Base2>>
> friend constexpr range_difference_t<_Base2>
> operator-(const _Iterator<_Const2>& __x, const _Sentinel& __y)
> { return __x._M_current - __y._M_end; }
> 
> 
> the return type of the function is range_difference_t<_Base2>, but in
> [range.elements#sentinel], it is defined as range_difference_t:
> 
> 
>   template
> requires sized_­sentinel_­for, iterator_t   const>>
>   friend constexpr range_difference_t
> operator-(const iterator& x, const sentinel& y);
> 
> 
> Perhaps range_difference_t and range_difference_t<_Base2> are
> equivalent in this case, but I am not sure.

This one is a problem with the WP.

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-17 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

Patrick Palka  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |ppalka at gcc dot 
gnu.org
 CC||ppalka at gcc dot gnu.org
   Last reconfirmed||2021-05-17

--- Comment #3 from Patrick Palka  ---
Confirmed.

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-16 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #2 from 康桓瑋  ---
In addition, I think elements_view::_Sentinel::_M_equal should be a template
function, and elements_view::_Iterator also needs to declare _Sentinel
as a friend, otherwise the following valid codes will be rejected:

https://godbolt.org/z/7aa75vqsP


#include 

int main() {
  auto r = std::views::iota(0)
| std::views::transform([](int) { return std::make_pair(42, "hello"); })
| std::views::keys;

  auto b = std::ranges::cbegin(r);
  auto e = std::end(r);
  b.base() == e.base();

  b == e; // error
}


:12:9:   required from here
/opt/compiler-explorer/gcc-trunk-20210513/include/c++/12.0.0/ranges:3675:34:
error: cannot convert 'const
std::ranges::elements_view, main():: >, 0>::_Iterator' to
'const
std::ranges::elements_view, main():: >, 0>::_Iterator&'
 3675 | { return __y._M_equal(__x); }
  |  ^
/opt/compiler-explorer/gcc-trunk-20210513/include/c++/12.0.0/ranges:3645:45:
note:   initializing argument 1 of 'constexpr bool
std::ranges::elements_view<_Vp, _Nm>::_Sentinel<_Const>::_M_equal(const
std::ranges::elements_view<_Vp, _Nm>::_Iterator<_Const>&) const [with bool
_Const = false; _Vp = std::ranges::transform_view, main():: >; long unsigned int _Nm =
0]'
 3645 |   _M_equal(const _Iterator<_Const>& __x) const
  |~^~~

[Bug libstdc++/100631] ranges::elements_view:: _Sentinel is missing __distance_from() that can access _M_current of _Iterator

2021-05-16 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100631

--- Comment #1 from 康桓瑋  ---
Another issue is that in elements_view::_Sentinel in ranges#L3677:


  template>
requires sized_sentinel_for, iterator_t<_Base2>>
friend constexpr range_difference_t<_Base2>
operator-(const _Iterator<_Const2>& __x, const _Sentinel& __y)
{ return __x._M_current - __y._M_end; }


the return type of the function is range_difference_t<_Base2>, but in
[range.elements#sentinel], it is defined as range_difference_t:


  template
requires sized_­sentinel_­for, iterator_t>>
  friend constexpr range_difference_t
operator-(const iterator& x, const sentinel& y);


Perhaps range_difference_t and range_difference_t<_Base2> are equivalent
in this case, but I am not sure.