Hi, std::sort() calls the comparator with out of bounds iterators when being passed a stupid comparator function (which returns always true for example).
I’m using xcode14.3 (clang version 14.0.3 (clang-1403.0.22.14.1))
At any optimisation level, -std=c++20
I wonder if it can be considered a bug in libc++ or an undefined behaviour?
Note that if I comment out the copy constructor, there’s no problem.
My app accepts user defined comparator functions, so I need to take care of such cases…
struct Value
{
Value():i(123) {}
Value( const Value& inOther):i(123){} // comment this line and it doesn't abort
int i;
};
std::vector<Value> v( 8);
std::sort( v.begin(), v.end(), []( auto& a1, auto& a2){
if (a1.i != 123 || a2.i != 123)
abort(); // got an invalid iterator!
return true;
});