Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22000

Expected compiler error when sorting std::list with -fconcepts on gcc trunk?

$
0
0

First, the source:

#include <list>#include <algorithm>using namespace std;int main(int argc, const char* argv[]) {    list<int> l = {3,-1,10};    sort(begin(l), end(l));    return 0;}

Following cppreference I was expecting to see an error similar to:

error: cannot call std::sort with std::_List_iterator<int>note:  concept RandomAccessIterator<std::_List_iterator<int>> was not satisfied

when compiling using following command:

$ /usr/local/bin/g++ --versiong++ (GCC) 7.0.1 20170401 (experimental)Copyright (C) 2017 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.$ /usr/local/bin/g++ -fconcepts concepts.cpp -o concepts

However, I see instead:

In file included from /usr/local/include/c++/7.0.1/algorithm:62:0,                 from concepts.cpp:2:/usr/local/include/c++/7.0.1/bits/stl_algo.h: In instantiation of ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’:/usr/local/include/c++/7.0.1/bits/stl_algo.h:4822:18:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = std::_List_iterator<int>]’concepts.cpp:8:26:   required from here/usr/local/include/c++/7.0.1/bits/stl_algo.h:1969:22: error: no match for ‘operator-’ (operand types are ‘std::_List_iterator<int>’ and ‘std::_List_iterator<int>’)     std::__lg(__last - __first) * 2,               ~~~~~~~^~~~~~~~~In file included from /usr/local/include/c++/7.0.1/bits/stl_algobase.h:67:0,                 from /usr/local/include/c++/7.0.1/list:60,                 from concepts.cpp:1:/usr/local/include/c++/7.0.1/bits/stl_iterator.h:389:5: note: candidate: template<class _IteratorL, class _IteratorR> decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)     operator-(const reverse_iterator<_IteratorL>& __x,     ^~~~~~~~/usr/local/include/c++/7.0.1/bits/stl_iterator.h:389:5: note:   template argument deduction/substitution failed:In file included from /usr/local/include/c++/7.0.1/algorithm:62:0,                 from concepts.cpp:2:/usr/local/include/c++/7.0.1/bits/stl_algo.h:1969:22: note:   ‘std::_List_iterator<int>’ is not derived from ‘const std::reverse_iterator<_Iterator>’     std::__lg(__last - __first) * 2,               ~~~~~~~^~~~~~~~~In file included from /usr/local/include/c++/7.0.1/bits/stl_algobase.h:67:0,                 from /usr/local/include/c++/7.0.1/list:60,                 from concepts.cpp:1:/usr/local/include/c++/7.0.1/bits/stl_iterator.h:1191:5: note: candidate: template<class _IteratorL, class _IteratorR> decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)     operator-(const move_iterator<_IteratorL>& __x,     ^~~~~~~~/usr/local/include/c++/7.0.1/bits/stl_iterator.h:1191:5: note:   template argument deduction/substitution failed:In file included from /usr/local/include/c++/7.0.1/algorithm:62:0,                 from concepts.cpp:2:/usr/local/include/c++/7.0.1/bits/stl_algo.h:1969:22: note:   ‘std::_List_iterator<int>’ is not derived from ‘const std::move_iterator<_IteratorL>’     std::__lg(__last - __first) * 2,               ~

... which is the output I would expect without concepts.


Viewing all articles
Browse latest Browse all 22000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>