Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does calling std::ranges::rotate on a vector result in a "no matching function call to '__begin'" error using clang 15?

I have the following function that does a rotation to a vector of char :

void rotate()
{
    std::ranges::rotate(_right, _right.begin() + 1);
}

_right is defined as :

 std::vector<char> _right;

trying to compile it with clang 15, it complains that (https://godbolt.org/z/7ovTfxe31):

 no matching function for call to '__begin'

the reason for that seems to be the following :

in instantiation of template type alias 'iterator_t' requested here
  requires contiguous_iterator<iterator_t<_Derived>>

but I assume that vector is a contiguous container. Code compiles and run with GCC.

Here are my questions:

  1. According to cppreference the above mentioned call should be a legitimate call or am I missing sth?
  2. If it is a legitimate call then is there any way to make the clang to accept the call like GCC?
like image 449
milad lashini Avatar asked Oct 26 '25 14:10

milad lashini


1 Answers

clang 15 and older compilers have issues with compiling libstdc++ algorithms due to how constraints are checked for satisfaction.

See LLVM Issue 44178: [concepts] deferred substitution into requirements of class template members not implemented. This is a known bug and has been resolved in clang 16.

Unlike GCC, clang doesn't defer instantiation of member constraints until member instantiation. In libstdc++'s __begin, the constraint __member_begin is not satisfied on the std::subrange created from the vector by std::rotate despite std::subrange obviously having a .begin() member. As a result, std::rotate can't be called.

like image 68
Jan Schultke Avatar answered Oct 29 '25 07:10

Jan Schultke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!