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

    <tr>
        <th>Summary</th>
        <td>
            PSTL test util uses moved-from iterators
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          jwakely
      </td>
    </tr>
</table>

<pre>
    The PSTL tests use this helper:

https://github.com/llvm/llvm-project/blob/24a804101b67676aa9fa7f1097043ddd9e2ac1b6/pstl/test/support/utils.h#L1083-L1099

It gets called with rvalue iterators like this:

https://github.com/llvm/llvm-project/blob/24a804101b67676aa9fa7f1097043ddd9e2ac1b6/pstl/test/std/algorithms/alg.sorting/alg.min.max/minmax_element.pass.cpp#L122

Line 1091 in the `reverse_invoker` forwards the rvalues and they are moved into the by-value parameters of the `operator()` call, leaving the original iterators in a moved-from state. Then line 1094 forwards them again, and they are moved into the by-value parameters of another `operator()` call.

With the libstdc++ Debug Mode, `std::vector::iterator` becomes singular after being moved from. That means they become singular after line 1091 and then line 1094 aborts.

[iterator.requirements.general] para 7 makes it clear that in the general case, it's not OK to copy or move a singular iterator. For a value-initialized iterator, it's OK. I don't see anything that says a moved-from `vector::iterator` can't become singular, so I think this is a bug in the PSTL tests.

It could be fixed by changing the by-value parameters of `iterator_invoker::operator()` to use forwarding references, or by making local copies of the iterators in `reverse_iterator::operator()` so that the originals are not moved-from, or by not forwarding the iterators in `reverse_iterator::operator()`, so that they are lvalue copies and don't modify the originals.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVc1u6zYTfRp6M4hAUbJsLbxIvsBAcPPhFmiALi9G0kjiNUWqHMqJ-_QFJdtxUmTRdtGNrR9q5pwzZ2aQWXeWaCfWD2L9uMIp9M7vfr7igcxpVbnmtHvpCX759eUZAnFgmJgg9JqhJzOSF9m9kI9Cnn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