[Bug libstdc++/64647] New: [5 Regression] [C++14] std::__max_element contains code not allowed in constexpr function

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Jan 17 18:01:00 GMT 2015


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

            Bug ID: 64647
           Summary: [5 Regression] [C++14] std::__max_element contains
                    code not allowed in constexpr function
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
                CC: ville.voutilainen at gmail dot com

#include <forward_list>
#include <algorithm>

int main()
{
  std::forward_list<int> v;
  std::max_element(v.begin(), v.end());
}

Compiling with -std=c++14 gives:

In file included from /home/jwakely/gcc/5/include/c++/5.0.0/algorithm:62:0,
                 from max.cc:2:
/home/jwakely/gcc/5/include/c++/5.0.0/bits/stl_algo.h: In instantiation of
‘constexpr _ForwardIterator std::__max_element(_ForwardIterator,
_ForwardIterator, _Compare) [with _ForwardIterator =
std::_Fwd_list_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’:
/home/jwakely/gcc/5/include/c++/5.0.0/bits/stl_algo.h:5514:43:   required from
‘constexpr _FIter std::max_element(_FIter, _FIter) [with _FIter =
std::_Fwd_list_iterator<int>]’
max.cc:7:38:   required from here
/home/jwakely/gcc/5/include/c++/5.0.0/bits/stl_algo.h:5489:35: error: variable
‘__result’ of non-literal type ‘std::_Fwd_list_iterator<int>’ in ‘constexpr’
function
       _ForwardIterator __result = __first;
                                   ^
In file included from /home/jwakely/gcc/5/include/c++/5.0.0/forward_list:38:0,
                 from max.cc:1:
/home/jwakely/gcc/5/include/c++/5.0.0/bits/forward_list.h:120:12: note:
‘std::_Fwd_list_iterator<int>’ is not literal because:
     struct _Fwd_list_iterator
            ^
/home/jwakely/gcc/5/include/c++/5.0.0/bits/forward_list.h:120:12: note:  
‘std::_Fwd_list_iterator<int>’ is not an aggregate, does not have a trivial
default constructor, and has no constexpr constructor that is not a copy or
move constructor


More information about the Gcc-bugs mailing list