Bug 93936 - [ranges] std::ranges::split_view<...>::_OuterIter<...>::__current() is private within this context
Summary: [ranges] std::ranges::split_view<...>::_OuterIter<...>::__current() is privat...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 10.0
Assignee: Patrick Palka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-25 23:06 UTC by Eric Niebler
Modified: 2020-02-26 22:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-02-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Niebler 2020-02-25 23:06:28 UTC
The following program fails to compile with -std=c++2a on gcc-trunk:

#include <ranges>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>

inline constexpr auto as_string = [](std::ranges::view auto rng) {
    auto in = rng | std::views::common;
    return std::string(in.begin(), in.end());
};

int main() {
    namespace views = std::views;
    std::string str = "Now is the time for all good men to come to the aid of their county.";
    auto rng = str | views::split(' ') | views::transform(as_string) | views::common;
    std::vector<std::string> words(rng.begin(), rng.end());
    std::ranges::copy(words, std::ostream_iterator<std::string>{std::cout,","});
}

The error is:

/opt/compiler-explorer/gcc-trunk-20200225/include/c++/10.0.1/ranges:2828:31: error: 'constexpr auto& std::ranges::split_view<_Vp, _Pattern>::_OuterIter<_Const>::__current() const [with bool _Const = true; _Vp = std::ranges::ref_view<std::__cxx11::basic_string<char> >; _Pattern = std::ranges::single_view<char>]' is private within this context

 2828 |    { return __x._M_i.__current() == __y._M_i.__current(); }

      |             ~~~~~~~~~~~~~~~~~~^~

Obligatory godbolt link: https://godbolt.org/z/B4tZPx
Comment 1 GCC Commits 2020-02-26 15:25:48 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:8ce13842b50cbd2676f2e322995182af20df31fe

commit r10-6871-g8ce13842b50cbd2676f2e322995182af20df31fe
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Feb 26 08:38:06 2020 -0500

    libstdc++: Fix use of inaccessible private member in split_view (PR93936)
    
    We are calling _OuterIter::__current from _InnerIter::operator==, but the former
    is private within this non-member friend.  Fix this by calling
    _OuterIter::operator== instead, which does the right thing here.
    
    libstdc++-v3/ChangeLog:
    
    	PR libstdc++/93936
    	* include/std/ranges (split_view::_InnerIter::operator==): Compare
    	the operands' _M_i rather than their _M_i.current().
    	* testsuite/std/ranges/adaptors/split.cc: Augment test.
Comment 2 Patrick Palka 2020-02-26 15:35:47 UTC
This should be fixed now.