The Comparator That Crashes

The C++ standard requires comp to induce a strict weak ordering, where strict means the relation is irreflexive: !comp(x, x) must hold for every x. A developer writes:

std::sort(tasks.begin(), tasks.end(),
          [](const Task &a, const Task &b) { return a.priority <= b.priority; });

reasoning that <= is "the same order, just including ties". The code passes on small test data and later crashes in production. What is the correct account?

A

It fails to compile, since std::sort requires a predicate that models a strict ordering

B

The comparator violates a precondition, so the behavior is undefined; the partition scan loses its sentinel and walks off the end of the range

C

The sort is still correct, it just stops being stable, so ties come out in an arbitrary order

D

It sorts in descending order, because <= inverts the sense of the predicate