[PATCH] libstdc++: Make forward_list::sort exception-safe [PR124051]

Jonathan Wakely jwakely@redhat.com
Wed Aug 19 11:19:55 GMT 2026


On Sun, 16 Aug 2026 at 20:43 +0000, Odysseas Georgoudis wrote:
>If a comparison called by forward_list::sort throws, the current
>implementation can leave the list corrupted, which may cause a later
>crash.
>
>This patch restores valid links before allowing the same exception to
>continue.  The element order remains unspecified, as permitted by the
>standard, while iterators and references remain valid.
>
>Tested on x86_64-pc-linux-gnu.
>
>Thanks,
>Odysseas

Thanks for the patch to fix this.

Have you tested whether this affects performance of the sort function?
I hope it doesn't make much difference.

Please don't attach patches as application/octet-stream - patches are
plain text, not binary data. It makes it hard to review the patch by
replying inline.

Please read
https://gcc.gnu.org/onlinedocs/libstdc++/manual/test.html#test.new_tests
and adjust the new test accordingly. Based on the copyright notice in
the test, it seems likely this was produced with the assistance of an
LLM, is that correct?



More information about the Libstdc++ mailing list