As explained in this email: https://gcc.gnu.org/pipermail/libstdc++/2024-April/058552.html I experimented -Wfree-nonheap-object because of my enhancements on algos. So here is a patch to extend the usage of the _Guard type to other parts of vector.     libstdc++: Use RAII to replace try/catch blocks     Move _Guard into std::vector declaration and use it to guard all calls to     vector _M_allocate.     Doing so the compiler has more visibility on what is done with the pointers     and do not raise anymore the -Wfree-nonheap-object warning.     libstdc++-v3/ChangeLog:             * include/bits/vector.tcc (_Guard): Move...             * include/bits/stl_vector.h: ...here.             (_M_allocate_and_copy): Use latter.             (_M_initialize_dispatch): Likewise and set _M_finish first from the result             of __uninitialize_fill_n_a that can throw.             (_M_range_initialize): Likewise. Tested under Linux x86_64, ok to commit ? François