https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108288
--- Comment #9 from CVS 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:b9479ddc7a28fb672ca67304a67d66524d8200a4 commit r13-5044-gb9479ddc7a28fb672ca67304a67d66524d8200a4 Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Jan 5 16:23:51 2023 +0000 libstdc++: Fix deadlock in debug iterator increment [PR108288] With -fno-elide-constructors the debug iterator post-increment and post-decrement operators are susceptible to deadlock. They take a mutex lock and then return a temporary, which also attempts to take a lock to attach itself to the sequence. If the return value and *this happen to collide and use the same mutex from the pool, then you get a deadlock trying to lock a mutex that is already held by the current thread. The solution is to construct the return value before taking the lock. The copy constructor and pre-inc/pre-dec operators already manage locks correctly, without deadlock, so just implement post-inc/post-dec in the conventional way, taking a copy then modifying *this, then returning the copy. libstdc++-v3/ChangeLog: PR libstdc++/108288 * include/debug/safe_iterator.h (_Safe_iterator::operator++(int)) (_Safe_iterator::operator--(int)): Do not hold lock around construction of return value.