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

            Bug ID: 93978
           Summary: A snippet using views::join fails to compile with -O1,
                    but succeeds with -O0
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

$ cat join.cc
#include <ranges>
#include <vector>

namespace ranges = std::ranges;
namespace views = std::views;

void
test()
{
  std::vector<std::string> x = {""};
  auto i = std::counted_iterator(x.begin(), 1);
  auto r = ranges::subrange{i, std::default_sentinel};
  auto v = r | views::join;
}
$ g++ -std=c++2a -O0 join.cc
$ g++ -std=c++2a -O1 join.c
...
/home/patrick/code/gcc/libstdc++-v3/include/std/ranges:112:16: error: static
assertion failed                                                                
  112 |  static_assert(view<_Derived>);                                         
      |                ^~~~~~~~~~~~~~                                           
/home/patrick/code/gcc/libstdc++-v3/include/std/ranges:112:16: note:
constraints not satisfied                                                       
In file included from
/home/patrick/code/gcc/libstdc++-v3/include/std/string:54,                      
                 from
/home/patrick/code/gcc/libstdc++-v3/include/bits/locale_classes.h:40,
                 from
/home/patrick/code/gcc/libstdc++-v3/include/bits/ios_base.h:41,                 
                 from
/home/patrick/code/gcc/libstdc++-v3/include/std/streambuf:41,                   
                 from
/home/patrick/code/gcc/libstdc++-v3/include/bits/streambuf_iterator.h:35,       
                 from
/home/patrick/code/gcc/libstdc++-v3/include/std/iterator:66,                    
                 from
/home/patrick/code/gcc/libstdc++-v3/include/std/ranges:44,                      
                 from join.cc:1:                                                
/home/patrick/code/gcc/libstdc++-v3/include/bits/range_access.h:880:13:  
required for the satisfaction of
‘range<std::ranges::join_view<std::ranges::subrange<std::counted_iterator<__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >*,
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > > > > >,
std::default_sentinel_t, std::ranges::subrange_kind::sized> > >’                
/home/patrick/code/gcc/libstdc++-v3/include/bits/range_access.h:880:21:   in
requirements with
‘std::ranges::join_view<std::ranges::subrange<std::counted_iterator<__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*,
std::vector<std::__cxx11::basic_string<char> > > >, std::default_sentinel_t,
std::ranges::subrange_kind::sized> >& __t’                                  
/home/patrick/code/gcc/libstdc++-v3/include/bits/range_access.h:883:13: note:
the required expression ‘std::ranges::__cust::end(__t)’ is invalid
  883 |  ranges::end(__t);                                                      
      |  ~~~~~~~~~~~^~~~~                                                       



If we uncomment the code in constraint.cc that replays constraint satisfication
failures during diagnostics, it turns out that ranges::end(__t); is invalid
ultimately because 

/home/patrick/code/gcc/libstdc++-v3/include/bits/range_access.h:437:26: error:
use of ‘constexpr auto std::ranges::join_view<_Vp>::end() [with _Vp =
std::ranges::subrange<std::counted_iterator<__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char>*,
std::vector<std::__cxx11::basic_string<char> > > >, std::default_sentinel_t,
std::ranges::subrange_kind::sized>]’ before deduction of ‘auto’                 
  437 |    { __decay_copy(__t.end()) }                                          
      |                   ~~~~~~~^~                                             


Removing the static_assert(view<_Derived>); from view_interface::_M_derived()
fixes the compilation failure, but I'm not sure why.

Reply via email to