public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work
@ 2021-09-02 20:28 raffael at casagrande dot ch
2021-09-02 21:36 ` [Bug libstdc++/102181] " redi at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: raffael at casagrande dot ch @ 2021-09-02 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
Bug ID: 102181
Summary: std::advance and std::views::iota<std::int64_t> don't
work
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: raffael at casagrande dot ch
Target Milestone: ---
The following simple program doesn't compile:
#include <ranges>
int main() {
using type = std::int64_t; // using type = int works!
auto v = std::ranges::iota_view(static_cast<type>(0),
static_cast<type>(100));
auto b = v.begin();
std::advance(b, static_cast<type>(1));
}
gcc version: 12.0.0 20210901 (experimental)
Error messages:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:
In instantiation of 'constexpr void std::advance(_InputIterator&, _Distance)
[with _InputIterator = std::ranges::iota_view<long int, long int>::_Iterator;
_Distance = long int]':
<source>:7:15: required from here
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:21:
error: no matching function for call to '__advance(std::ranges::iota_view<long
int, long int>::_Iterator&, std::__iterator_traits<std::ranges::iota_view<long
int, long int>::_Iterator, void>::difference_type&,
std::__iterator_traits<std::ranges::iota_view<long int, long int>::_Iterator,
void>::iterator_category)'
207 | std::__advance(__i, __d, std::__iterator_category(__i));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:148:5:
note: candidate: 'template<class _InputIterator, class _Distance> constexpr
void std::__advance(_InputIterator&, _Distance, std::input_iterator_tag)'
148 | __advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
| ^~~~~~~~~
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:148:5:
note: template argument deduction/substitution failed:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:56:
note: cannot convert 'std::__iterator_category<std::ranges::iota_view<long
int, long int>::_Iterator>((*(const std::ranges::iota_view<long int, long
int>::_Iterator*)(& __i)))' (type
'std::__iterator_traits<std::ranges::iota_view<long int, long int>::_Iterator,
void>::iterator_category' {aka 'std::output_iterator_tag'}) to type
'std::input_iterator_tag'
207 | std::__advance(__i, __d, std::__iterator_category(__i));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:159:5:
note: candidate: 'template<class _BidirectionalIterator, class _Distance>
constexpr void std::__advance(_BidirectionalIterator&, _Distance,
std::bidirectional_iterator_tag)'
159 | __advance(_BidirectionalIterator& __i, _Distance __n,
| ^~~~~~~~~
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:159:5:
note: template argument deduction/substitution failed:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:56:
note: cannot convert 'std::__iterator_category<std::ranges::iota_view<long
int, long int>::_Iterator>((*(const std::ranges::iota_view<long int, long
int>::_Iterator*)(& __i)))' (type
'std::__iterator_traits<std::ranges::iota_view<long int, long int>::_Iterator,
void>::iterator_category' {aka 'std::output_iterator_tag'}) to type
'std::bidirectional_iterator_tag'
207 | std::__advance(__i, __d, std::__iterator_category(__i));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:175:5:
note: candidate: 'template<class _RandomAccessIterator, class _Distance>
constexpr void std::__advance(_RandomAccessIterator&, _Distance,
std::random_access_iterator_tag)'
175 | __advance(_RandomAccessIterator& __i, _Distance __n,
| ^~~~~~~~~
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:175:5:
note: template argument deduction/substitution failed:
/opt/compiler-explorer/gcc-trunk-20210902/include/c++/12.0.0/bits/stl_iterator_base_funcs.h:207:56:
note: cannot convert 'std::__iterator_category<std::ranges::iota_view<long
int, long int>::_Iterator>((*(const std::ranges::iota_view<long int, long
int>::_Iterator*)(& __i)))' (type
'std::__iterator_traits<std::ranges::iota_view<long int, long int>::_Iterator,
void>::iterator_category' {aka 'std::output_iterator_tag'}) to type
'std::random_access_iterator_tag'
207 | std::__advance(__i, __d, std::__iterator_category(__i));
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
@ 2021-09-02 21:36 ` redi at gcc dot gnu.org
2021-09-02 21:44 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-02 21:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It compiles with -std=gnu++20 but not -std=c++20
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
2021-09-02 21:36 ` [Bug libstdc++/102181] " redi at gcc dot gnu.org
@ 2021-09-02 21:44 ` redi at gcc dot gnu.org
2021-09-02 21:51 ` raffael at casagrande dot ch
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-02 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
You need to use std::ranges::advance here, because iota_view is "special".
The reason std::advance doesn't work is that the type of v.begin() does not
meet the Cpp17InputIterator requirements, because its difference_type is
__int128, which is not a signed integer type when using -std=c++17 (but it is
when using -std=gnu++20). Failing to meet the Cpp17InputIterator requirements
means that std::iterator_traits<decltype(b)>::iterator_category defaults to
output_iterator_tag. And you can't advance an output iterator.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
2021-09-02 21:36 ` [Bug libstdc++/102181] " redi at gcc dot gnu.org
2021-09-02 21:44 ` redi at gcc dot gnu.org
@ 2021-09-02 21:51 ` raffael at casagrande dot ch
2021-09-02 21:59 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: raffael at casagrande dot ch @ 2021-09-02 21:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
--- Comment #3 from Raffael Casagrande <raffael at casagrande dot ch> ---
thanks for the fast response. I can switch over to std::ranges::advance.
MSVC compiles the snippet without problems...
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
` (2 preceding siblings ...)
2021-09-02 21:51 ` raffael at casagrande dot ch
@ 2021-09-02 21:59 ` redi at gcc dot gnu.org
2021-09-02 22:13 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-02 21:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://en.cppreference.com/w/cpp/iterator/advance says "InputIt must meet the
requirements of LegacyInputIterator."
https://en.cppreference.com/w/cpp/named_req/InputIterator gives a sample
concept you can use to test whether something meets those requirements. The
iterator_t<iota_view<int64_t, int64_t>> type does not satisfy that concept.
I think GCC is behaving according to the standard.
You can use std::ranges::advance because that requires
std::input_or_output_iterator, which is satisfied by your iota_view's iterator.
#include <ranges>
int main() {
using type = std::int64_t; // using type = int works!
auto v = std::views::iota(static_cast<type>(0), static_cast<type>(100));
auto b = v.begin();
static_assert( ! __LegacyInputIterator<decltype(b)> );
// So this can't work:
// std::advance(b, 1);
static_assert( std::input_iterator<decltype(b)> );
// So this can work:
std::ranges::advance(b, static_cast<type>(1));
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
` (3 preceding siblings ...)
2021-09-02 21:59 ` redi at gcc dot gnu.org
@ 2021-09-02 22:13 ` redi at gcc dot gnu.org
2021-09-02 23:35 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-02 22:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Raffael Casagrande from comment #3)
> MSVC compiles the snippet without problems...
It looks like they do not correctly implement iota_view. This C++20 proposal,
specifically:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1522r1.pdf
This program fails with MSVC:
#include <ranges>
int main() {
using type = uint64_t; // using type = int works!
auto v = std::views::iota(0ull, ~0ull);
auto b = v.end() - v.begin();
static_assert(!std::same_as<decltype(b), int64_t>);
}
It is required to compile. You cannot use int64_t to represent the difference
type of an iota_view with that many elements.
I think GCC is correct according to the standard.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
` (4 preceding siblings ...)
2021-09-02 22:13 ` redi at gcc dot gnu.org
@ 2021-09-02 23:35 ` redi at gcc dot gnu.org
2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:11 ` [Bug libstdc++/102181] [DR 3197] " redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-02 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Ever confirmed|0 |1
Resolution|INVALID |---
Last reconfirmed| |2021-09-02
Status|RESOLVED |ASSIGNED
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reopening, because we can make this Just Work, even though we're not required
to.
--- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
@@ -211,7 +222,11 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
{
// concept requirements -- taken care of in __advance
typename iterator_traits<_InputIterator>::difference_type __d = __n;
+#if __cpp_lib_concepts
+ std::__advance(__i, __d, __detail::__iter_concept<_InputIterator>{});
+#else
std::__advance(__i, __d, std::__iterator_category(__i));
+#endif
}
#if __cplusplus >= 201103L
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
` (5 preceding siblings ...)
2021-09-02 23:35 ` redi at gcc dot gnu.org
@ 2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:11 ` [Bug libstdc++/102181] [DR 3197] " redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-12 15:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:d9dfd7ad3e0196f60a3fc6df6d65a40fb905409f
commit r12-4355-gd9dfd7ad3e0196f60a3fc6df6d65a40fb905409f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Sep 29 21:19:36 2021 +0100
libstdc++: Improve diagnostics for misuses of output iterators
This adds deleted overloads so that the errors for invalid uses of
std::advance and std::distance are easier to understand (see for example
PR 102181).
libstdc++-v3/ChangeLog:
* include/bits/stl_iterator_base_funcs.h (__advance): Add
deleted overload to improve diagnostics.
(__distance): Likewise.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/102181] [DR 3197] std::advance and std::views::iota<std::int64_t> don't work
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
` (6 preceding siblings ...)
2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
@ 2021-10-12 16:11 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-12 16:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102181
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |SUSPENDED
Summary|std::advance and |[DR 3197] std::advance and
|std::views::iota<std::int64 |std::views::iota<std::int64
|_t> don't work |_t> don't work
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Suspending until https://wg21.link/lwg3197 is resolved.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-10-12 16:11 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02 20:28 [Bug libstdc++/102181] New: std::advance and std::views::iota<std::int64_t> don't work raffael at casagrande dot ch
2021-09-02 21:36 ` [Bug libstdc++/102181] " redi at gcc dot gnu.org
2021-09-02 21:44 ` redi at gcc dot gnu.org
2021-09-02 21:51 ` raffael at casagrande dot ch
2021-09-02 21:59 ` redi at gcc dot gnu.org
2021-09-02 22:13 ` redi at gcc dot gnu.org
2021-09-02 23:35 ` redi at gcc dot gnu.org
2021-10-12 15:49 ` cvs-commit at gcc dot gnu.org
2021-10-12 16:11 ` [Bug libstdc++/102181] [DR 3197] " redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).