[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 --- Comment #5 from GCC Commits --- The releases/gcc-13 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:47ebdbe5bf71d9eb260359b6aceb5cb071d97acd commit r13-8570-g47ebdbe5bf71d9eb260359b6aceb5cb071d97acd Author: Jonathan Wakely Date: Thu Mar 21 13:25:15 2024 + libstdc++: Destroy allocators in re-inserted container nodes [PR114401] The allocator objects in container node handles were not being destroyed after the node was re-inserted into a container. They are stored in a union and so need to be explicitly destroyed when the node becomes empty. The containers were zeroing the node handle's pointer, which makes it empty, causing the handle's destructor to think there's nothing to clean up. Add a new member function to the node handle which destroys the allocator and zeros the pointer. Change the containers to call that instead of just changing the pointer manually. We can also remove the _M_empty member of the union which is not necessary. libstdc++-v3/ChangeLog: PR libstdc++/114401 * include/bits/hashtable.h (_Hashtable::_M_reinsert_node): Call release() on node handle instead of just zeroing its pointer. (_Hashtable::_M_reinsert_node_multi): Likewise. (_Hashtable::_M_merge_unique): Likewise. (_Hashtable::_M_merge_multi): Likewise. * include/bits/node_handle.h (_Node_handle_common::release()): New member function. (_Node_handle_common::_Optional_alloc::_M_empty): Remove unnecessary union member. (_Node_handle_common): Declare _Hashtable as a friend. * include/bits/stl_tree.h (_Rb_tree::_M_reinsert_node_unique): Call release() on node handle instead of just zeroing its pointer. (_Rb_tree::_M_reinsert_node_equal): Likewise. (_Rb_tree::_M_reinsert_node_hint_unique): Likewise. (_Rb_tree::_M_reinsert_node_hint_equal): Likewise. * testsuite/23_containers/multiset/modifiers/114401.cc: New test. * testsuite/23_containers/set/modifiers/114401.cc: New test. * testsuite/23_containers/unordered_multiset/modifiers/114401.cc: New test. * testsuite/23_containers/unordered_set/modifiers/114401.cc: New test. (cherry picked from commit c2e28df90a1640cebadef6c6c8ab5ea964071bb1)
[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 --- Comment #4 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #2) > There's another bug in the node move assignment operator, so I'll fix that > too. Turns out there wasn't, just the one you reported originally. It's fixed on trunk, but I'll backport it to the release branches.
[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 --- Comment #3 from GCC Commits --- The master branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:c2e28df90a1640cebadef6c6c8ab5ea964071bb1 commit r14-9636-gc2e28df90a1640cebadef6c6c8ab5ea964071bb1 Author: Jonathan Wakely Date: Thu Mar 21 13:25:15 2024 + libstdc++: Destroy allocators in re-inserted container nodes [PR114401] The allocator objects in container node handles were not being destroyed after the node was re-inserted into a container. They are stored in a union and so need to be explicitly destroyed when the node becomes empty. The containers were zeroing the node handle's pointer, which makes it empty, causing the handle's destructor to think there's nothign to clean up. Add a new member function to the node handle which destroys the allocator and zeros the pointer. Change the containers to call that instead of just changing the pointer manually. We can also remove the _M_empty member of the union which is not necessary. libstdc++-v3/ChangeLog: PR libstdc++/114401 * include/bits/hashtable.h (_Hashtable::_M_reinsert_node): Call release() on node handle instead of just zeroing its pointer. (_Hashtable::_M_reinsert_node_multi): Likewise. (_Hashtable::_M_merge_unique): Likewise. (_Hashtable::_M_merge_multi): Likewise. * include/bits/node_handle.h (_Node_handle_common::release()): New member function. (_Node_handle_common::_Optional_alloc::_M_empty): Remove unnecessary union member. (_Node_handle_common): Declare _Hashtable as a friend. * include/bits/stl_tree.h (_Rb_tree::_M_reinsert_node_unique): Call release() on node handle instead of just zeroing its pointer. (_Rb_tree::_M_reinsert_node_equal): Likewise. (_Rb_tree::_M_reinsert_node_hint_unique): Likewise. (_Rb_tree::_M_reinsert_node_hint_equal): Likewise. * testsuite/23_containers/multiset/modifiers/114401.cc: New test. * testsuite/23_containers/set/modifiers/114401.cc: New test. * testsuite/23_containers/unordered_multiset/modifiers/114401.cc: New test. * testsuite/23_containers/unordered_set/modifiers/114401.cc: New test.
[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 --- Comment #2 from Jonathan Wakely --- There's another bug in the node move assignment operator, so I'll fix that too.
[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 Jonathan Wakely changed: What|Removed |Added Target Milestone|--- |11.5 Keywords||wrong-code
[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 Jonathan Wakely changed: What|Removed |Added Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org Status|NEW |ASSIGNED --- Comment #1 from Jonathan Wakely --- Created attachment 57748 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57748=edit Untested patch to fix all assoc containers Thanks for the report and analysis. This should do it.
[Bug libstdc++/114401] libstdc++ allocator destructor omitted when reinserting node_handle into tree- and hashtable-based containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114401 Jonathan Wakely changed: What|Removed |Added Last reconfirmed||2024-03-20 Status|UNCONFIRMED |NEW Ever confirmed|0 |1