<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63153>63153</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            libc++ hardening: check for sorted/heapified input in debug mode
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          var-const
      </td>
    </tr>
</table>

<pre>
    Certain algorithms have a precondition that the provided input satisfies a certain criterion:
- is sorted (`merge`, `inplace_merge`, `includes`, set_union`, `set_intersection`, `set_difference`, `set_symmetric_difference`);
- is heapified (`push_heap`, `pop_heap`, `sort_heap`);
- is partitioned (`partition_point`, `lower_bound`, `upper_bound`, `equal_range`, `binary_search`).

We could add a group of assertions for checking these criteria. Since these cannot be done in constant time, this group would probably only be enabled in debug mode.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkk9-OqzgMxp8m3FitIFC2XHAxc476Anuxl5WTGPBuSLJJ6KhvfwTtDPNHQiD9iD9_dmxMiUdH1IvTqzj9LnDJk4_9DeNBe5dyoby5978oZmQHaEcfOU9zgglvBAghkvbOcGbvIE-YIU8EIfobGzLALiwZEmZOA1MCBP2U0pEzRfZO1C-i_C3KlwNwguRjJgNCnkVbzhRHEm0p5C8QbckuWNR0_YG1XQylJ0mUr4tbhT9OrIhdpphI5x9_DA8DRXKavvJ0n2fKkfX3E52oXz9ZnggDD_zhOixpuq5wlws-fCNrnTv6phgw5q2ju-Y7uQbPLu861r9RvCq_OLPDJYSfkP5f0F4jus-9U-ww3q-JMOrpYeX4MPJ4_0Og_WINoDGAMEa_BPADYEoUVz8JBh9BT6T_Yzeul5_o_W7xCH-z0_RO0TmfQREY7wjWGVgnDF2GzDOtjvLE6ZnkbUsboleo7B28s_c1lBwquw0WGFLLCLM3dCxMX5uu7rCgvmrPbfnXqaqaYurbc6VQ46lSlZRd3RlFne7OisrzUFeDKriXpazLtmyrc1WdmmNj6ratsRsapKaqG9GUNCPbo7W3-ejjWHBKC_VtXZ3qwqIim7blkdKy0kK-bo9clyn2a9BBLWMSTWk55bTLZM6W-j0GJoyGHLtR1C-Pjm69fWyEkJd9zh5b9aUFxRJtP-Uc0rpP8iLkZeQ8Leqo_SzkZU37_BxC9P-SzkJetlKSkJetmj8BAAD__7AOUGI">