https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118088
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-13 branch has been updated by Jonathan Wakely <[email protected]>: https://gcc.gnu.org/g:5d54e351e405e872be47352611bd1b6ea285b00c commit r13-10312-g5d54e351e405e872be47352611bd1b6ea285b00c Author: Jonathan Wakely <[email protected]> Date: Sat Dec 14 01:17:27 2024 +0000 libstdc++: Clear std::priority_queue after moving from it [PR118088] We don't know what state an arbitrary sequence container will be in after moving from it, so a moved-from std::priority_queue needs to clear the moved-from container to ensure it doesn't contain elements that are in an invalid order for the queue. An alternative would be to call std::make_heap again to re-establish the rvalue queue's invariant, but that could potentially cause an exception to be thrown. Just clearing it so the sequence is empty seems safer and more likely to match user expectations. libstdc++-v3/ChangeLog: PR libstdc++/118088 * include/bits/stl_queue.h (priority_queue(priority_queue&&)): Clear the source object after moving from it. (priority_queue(priority_queue&&, const Alloc&)): Likewise. (operator=(priority_queue&&)): Likewise. * testsuite/23_containers/priority_queue/118088.cc: New test. Reviewed-by: Patrick Palka <[email protected]> (cherry picked from commit 15aab0d00ca1ed5ce428555bf89ecfe0525f9b81)
