[cfe-users] Compiling C++ 20 Example from 24.6.4.1 [range.istream.overview] produces errors with libstdc++ 10

Richard Smith via cfe-users cfe-users at lists.llvm.org
Fri May 15 15:53:41 PDT 2020


On Thu, 14 May 2020 at 03:50, Ray Lischner <ray at klipp-lischner.net> wrote:

> On 5/13/20 10:09 PM, Richard Smith wrote:
> > On Wed, 6 May 2020 at 09:24, Ray Lischner via cfe-users
> > <cfe-users at lists.llvm.org <mailto:cfe-users at lists.llvm.org>> wrote:
> >
> >     I am using clang++ 10 with GCC libstdc++ 10 prerelease. I tried
> >     compiling the example from section 24.6.4.1
> >     [range.istream.overview]. It
> >     works with g++ 10 but with clang++ 10 -std=c++20, I get
> >     constraint-failure errors.
> >
> >     program:
> >     #include <algorithm>
> >     #include <iostream>
> >     #include <iterator>
> >     #include <ranges>
> >     #include <sstream>
> >
> >     int main()
> >     {
> >         using namespace std;
> >         using namespace ranges;
> >         auto ints = istringstream{"0 1  2   3     4"};
> >         ranges::copy(istream_view<int>(ints),
> >     ostream_iterator<int>{cout, "-"});
> >         // prints0-1-2-3-4-
> >     }
> >
> >     $ clang++ -std=c++20 -o range_istream_overview \
> >     range_istream_overview.cpp
> >
> >     Gist of the errors is that the istream_view fails the constraints
> for a
> >     range because ranges::begin() fails its constraint for the
> >     basic_istream_view::begin() member function:
> >
> >     { __detail::__decay_copy(__t.begin()) } -> input_or_output_iterator;
> >
> >     Any ideas what's wrong or how to proceed?
> >
> >
> > Please could you provide the complete set of diagnostics from the
> > compilation?
>
> In file included from range_istream_overview.cpp:1:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/algorithm:61:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/stl_algobase.h:65:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:71:
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:884:13:
>
> error: no matching function for call to '__ranges_begin'
>          = decltype(__detail::__ranges_begin(std::declval<_Tp&>()));
>                     ^~~~~~~~~~~~~~~~~~~~~~~~
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/range_access.h:874:5:
>
> note: in instantiation of template type alias '__range_iter_t' requested
> here
>      using iterator_t = std::__detail::__range_iter_t<_Tp>;
>      ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:134:43:
>
> note: in instantiation of template type alias 'iterator_t' requested here
>        data() requires contiguous_iterator<iterator_t<_Derived>>
>                                            ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:956:14:
>
> note: in instantiation of template class
> 'std::ranges::view_interface<std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > >' requested here
>      : public view_interface<basic_istream_view<_Val, _CharT, _Traits>>
>               ^
> range_istream_overview.cpp:12:16: note: in instantiation of template
> class 'std::ranges::basic_istream_view<int, char, std::char_traits<char>
>  >' requested here
>    ranges::copy(istream_view<int>(ints), ostream_iterator<int>{cout, "-"});
>                 ^
>

OK, so the relevant part is this:


> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:867:7:
>
> note: candidate template ignored: constraints not satisfied [with _Tp =
> std::ranges::basic_istream_view<int, char, std::char_traits<char> >]
>        __ranges_begin(_Tp& __t)
>        ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:865:16:
>
> note: because 'is_array_v<std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > >' evaluated to false
>        requires is_array_v<_Tp> || __member_begin<_Tp&> ||
> __adl_begin<_Tp&>
>                 ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:865:35:
>
> note: and 'std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > &' does not satisfy '__member_begin'
>        requires is_array_v<_Tp> || __member_begin<_Tp&> ||
> __adl_begin<_Tp&>
>                                    ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:849:33:
>
> note: because '__detail::__decay_copy(__t.begin())' would be invalid: no
> member named 'begin' in 'std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >'
>            { __detail::__decay_copy(__t.begin()) } ->
> input_or_output_iterator;
>                                         ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:865:59:
>
> note: and 'std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > &' does not satisfy '__adl_begin'
>        requires is_array_v<_Tp> || __member_begin<_Tp&> ||
> __adl_begin<_Tp&>
>                                                            ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:859:29:
>
> note: because '__detail::__decay_copy(begin(__t))' would be invalid:
> call to deleted function 'begin'
>            { __detail::__decay_copy(begin(__t)) } ->
> input_or_output_iterator;
>                                     ^
>

Just as you said, it looks like the problem is that
__member_begin<istream_view<int>&> is evaluating to 'false', whereas it
presumably should evaluate to 'true'.

Can you try calling begin() on an istream_view<int>& directly, and see if
you get the same error?

A heavily-reduced testcase doesn't demonstrate the problem --
https://godbolt.org/z/Np4EMg -- so I imagine there's something else
required to trigger this behavior. A more-reduced testcase should make the
problem easier to understand.


> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:884:13:
>
> error: no matching function for call to '__ranges_begin'
>          = decltype(__detail::__ranges_begin(std::declval<_Tp&>()));
>                     ^~~~~~~~~~~~~~~~~~~~~~~~
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/range_access.h:874:5:
>
> note: in instantiation of template type alias '__range_iter_t' requested
> here
>      using iterator_t = std::__detail::__range_iter_t<_Tp>;
>      ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:140:25:
>
> note: in instantiation of template type alias 'iterator_t' requested here
>          && contiguous_iterator<iterator_t<const _Derived>>
>                                 ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:956:14:
>
> note: in instantiation of template class
> 'std::ranges::view_interface<std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > >' requested here
>      : public view_interface<basic_istream_view<_Val, _CharT, _Traits>>
>               ^
> range_istream_overview.cpp:12:16: note: in instantiation of template
> class 'std::ranges::basic_istream_view<int, char, std::char_traits<char>
>  >' requested here
>    ranges::copy(istream_view<int>(ints), ostream_iterator<int>{cout, "-"});
>                 ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:867:7:
>
> note: candidate template ignored: constraints not satisfied [with _Tp =
> const std::ranges::basic_istream_view<int, char, std::char_traits<char> >]
>        __ranges_begin(_Tp& __t)
>        ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:865:16:
>
> note: because 'is_array_v<const std::ranges::basic_istream_view<int,
> char, std::char_traits<char> > >' evaluated to false
>        requires is_array_v<_Tp> || __member_begin<_Tp&> ||
> __adl_begin<_Tp&>
>                 ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:865:35:
>
> note: and 'const std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > &' does not satisfy '__member_begin'
>        requires is_array_v<_Tp> || __member_begin<_Tp&> ||
> __adl_begin<_Tp&>
>                                    ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:849:33:
>
> note: because '__detail::__decay_copy(__t.begin())' would be invalid: no
> member named 'begin' in 'std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >'
>            { __detail::__decay_copy(__t.begin()) } ->
> input_or_output_iterator;
>                                         ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:865:59:
>
> note: and 'const std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > &' does not satisfy '__adl_begin'
>        requires is_array_v<_Tp> || __member_begin<_Tp&> ||
> __adl_begin<_Tp&>
>                                                            ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/iterator_concepts.h:859:29:
>
> note: because '__detail::__decay_copy(begin(__t))' would be invalid:
> call to deleted function 'begin'
>            { __detail::__decay_copy(begin(__t)) } ->
> input_or_output_iterator;
>                                     ^
> In file included from range_istream_overview.cpp:1:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/algorithm:64:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/ranges_algo.h:35:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/ranges_algobase.h:38:
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:146:24:
>
> error: constraints not satisfied for alias template 'sentinel_t' [with
> _Range = std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >]
>          && sized_sentinel_for<sentinel_t<_Derived>, iterator_t<_Derived>>
>                                ^~~~~~~~~~~~~~~~~~~~
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:956:14:
>
> note: in instantiation of template class
> 'std::ranges::view_interface<std::ranges::basic_istream_view<int, char,
> std::char_traits<char> > >' requested here
>      : public view_interface<basic_istream_view<_Val, _CharT, _Traits>>
>               ^
> range_istream_overview.cpp:12:16: note: in instantiation of template
> class 'std::ranges::basic_istream_view<int, char, std::char_traits<char>
>  >' requested here
>    ranges::copy(istream_view<int>(ints), ostream_iterator<int>{cout, "-"});
>                 ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/range_access.h:876:12:
>
> note: because 'std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >' does not satisfy 'range'
>    template<range _Range>
>             ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/range_access.h:864:2:
>
> note: because 'ranges::begin(__t)' would be invalid: no matching
> function for call to object of type 'const __cust_access::_Begin'
>          ranges::begin(__t);
>          ^
> In file included from range_istream_overview.cpp:1:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/algorithm:64:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/ranges_algo.h:35:
> In file included from
>
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/ranges_algobase.h:38:
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/ranges:152:24:
>
> error: constraints not satisfied for alias template 'sentinel_t' [with
> _Range = const std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >]
>          && sized_sentinel_for<sentinel_t<const _Derived>,
>                                ^~~~~~~~~~~~~~~~~~~~~~~~~~
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/range_access.h:876:12:
>
> note: because 'const std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >' does not satisfy 'range'
>    template<range _Range>
>             ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/range_access.h:864:2:
>
> note: because 'ranges::begin(__t)' would be invalid: no matching
> function for call to object of type 'const __cust_access::_Begin'
>          ranges::begin(__t);
>          ^
> range_istream_overview.cpp:12:3: error: no matching function for call to
> object of type 'const std::ranges::__copy_fn'
>    ranges::copy(istream_view<int>(ints), ostream_iterator<int>{cout, "-"});
>    ^~~~~~~~~~~~
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/ranges_algobase.h:309:7:
>
> note: candidate template ignored: substitution failure [with _Range =
> std::ranges::basic_istream_view<int, char, std::char_traits<char> >,
> _Out = std::ostream_iterator<int, char, std::char_traits<char> >]:
> constraints not satisfied for alias template 'borrowed_iterator_t' [with
> _Range = std::ranges::basic_istream_view<int, char,
> std::char_traits<char> >]
>        operator()(_Range&& __r, _Out __result) const
>        ^
> /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/bits/ranges_algobase.h:299:7:
>
> note: candidate function template not viable: requires 3 arguments, but
> 2 were provided
>        operator()(_Iter __first, _Sent __last, _Out __result) const
>        ^
> 5 errors generated.
>
> --
> Ray Lischner
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20200515/c5f3a705/attachment-0001.html>


More information about the cfe-users mailing list