[Bug libstdc++/93651] New: std::ranges::iota_view<long, long>::iterator is not a Cpp17 input iterator

pilarlatiesa at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Feb 10 12:36:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93651

            Bug ID: 93651
           Summary: std::ranges::iota_view<long, long>::iterator is not a
                    Cpp17 input iterator
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pilarlatiesa at gmail dot com
  Target Milestone: ---

In my understanding, std::ranges::iota_view<long, long>::iterator should model
at least Cpp17InputIterator, but it doesn't. In contrast,
std::ranges::iota_view<int, int>::iterator is accepted as an input iterator.

I surfaced the issue in -std=c++2a, while it does not happen with -std=gnu++2a,
which makes me think it is possibly related to  __iota_diff_t being defined as
__int128 (PR 93267).

Below there's an example showing the issue.

$ cat test1.cpp

#include <vector>
#include <ranges>

int main()
{
  std::ranges::iota_view<std::size_t, std::size_t> const i(0, 10u);
  std::vector<std::size_t> v(std::begin(i), std::end(i));
}

$ cat test2.cpp

#include <vector>
#include <ranges>

int main()
{
  std::ranges::iota_view<int, int> const i(0, 10u);
  std::vector<std::size_t> v(std::begin(i), std::end(i));
}

./g++ -std=gnu++2a -c test2.cpp

no output

./g++ -std=c++2a -c test2.cpp

no output

./g++ -std=gnu++2a -c test1.cpp

no output

./g++ -std=c++2a -c test1.cpp

test1.cpp: In function 'int main()':
test1.cpp:7:56: error: no matching function for call to 'std::vector<long
unsigned int>::vector(std::ranges::iota_view<long unsigned int, long unsigned
int>::_Iterator, std::ranges::iota_view<long unsigned int, long unsigned
int>::_Iterator)'
    7 |   std::vector<std::size_t> v(std::begin(i), std::end(i));
      |                                                        ^
In file included from
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/vector:67,
                 from test1.cpp:1:
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/stl_vector.h:650:2:
note: candidate: 'template<class _InputIterator, class> std::vector<_Tp,
_Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with
_InputIterator = _InputIterator; <template-parameter-2-2> =
<template-parameter-1-2>; _Tp = long unsigned int; _Alloc = std::allocator<long
unsigned int>]'
  650 |  vector(_InputIterator __first, _InputIterator __last,
      |  ^~~~~~
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/stl_vector.h:650:2:
note:   template argument deduction/substitution failed:
In file included from
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/move.h:57,
                 from
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/stl_pair.h:59,
                 from
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/stl_algobase.h:64,
                 from
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/vector:60,
                 from test1.cpp:1:
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/type_traits: In
substitution of 'template<bool _Cond, class _Tp> using __enable_if_t = typename
std::enable_if::type [with bool _Cond = false; _Tp = void]':
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/stl_iterator_base_types.h:249:11:
  required by substitution of 'template<class _InIter> using _RequireInputIter
= std::__enable_if_t<std::is_convertible<typename
std::iterator_traits<_Iterator>::iterator_category,
std::input_iterator_tag>::value> [with _InIter = std::ranges::iota_view<long
unsigned int, long unsigned int>::_Iterator]'
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/bits/stl_vector.h:649:9:
  required from here
/home/pililatiesa/gcc-trunk-20200208/include/c++/10.0.1/type_traits:2191:11:
error: no type named 'type' in 'struct std::enable_if<false, void>'
 2191 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~~~

[...] (The error message continues listing the other constructors)


g++ -v

Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk-20200208/configure --prefix=/usr
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--disable-bootstrap --with-abi=m64 --enable-clocale=gnu
--enable-languages=c,c++,fortran --enable-ld=yes --enable-checking=release
--enable-lto --enable-threads=posix --enable-libatomic --enable-libcilkrts
--enable-libgomp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200208 (experimental) (GCC)


More information about the Gcc-bugs mailing list