Clang vs gcc std :: crbegin with boost :: iterator_range

Clang 3.8.1 with libC ++ compiles the following program:

#include <vector> #include <iterator> #include <algorithm> #include <iostream> #include <boost/range/iterator_range.hpp> int main() { const std::vector<int> v {1, 2, 3}; const auto range = boost::make_iterator_range(v); std::copy(std::crbegin(range), std::crend(range), std::ostream_iterator<int> {std::cout, " "}); std::cout << std::endl; return 0; } 

But gcc 6.1.0 with libstdc ++ does not. First line of gcc error:

 error: no matching function for call to 'crbegin(const boost::iterator_range<__gnu_cxx::__normal_iterator<const int*, std::vector<int> > >& 

Who is right?

Note : Boost version 1.61

+6
source share
1 answer

This is a bug in libC ++ ; std::crbegin delegates rbegin , but, calling it unqualified, it raises boost::rbegin ( documentation ):

 template <class _Cp> inline _LIBCPP_INLINE_VISIBILITY auto crbegin(const _Cp& __c) -> decltype(rbegin(__c)) { return rbegin(__c); // ^-- unqualified, allows ADL } 

This contradicts [iterator.range] , which states that crbegin should only delegate std::rbegin :

template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));

14 - Returns: std::rbegin(c) .

LibC ++ cbegin , cend and crend have the same error.

+11
source

All Articles