https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118088

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>:

https://gcc.gnu.org/g:15aab0d00ca1ed5ce428555bf89ecfe0525f9b81

commit r15-6347-g15aab0d00ca1ed5ce428555bf89ecfe0525f9b81
Author: Jonathan Wakely <jwak...@redhat.com>
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 <ppa...@redhat.com>

Reply via email to