]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: fix element construction in std::deque::emplace [PR118087]
authorBen Wu <soggysocks206@gmail.com>
Fri, 19 Sep 2025 00:25:41 +0000 (17:25 -0700)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 23 Sep 2025 15:38:28 +0000 (16:38 +0100)
commit52d702d72afa0ade8edfff144b45539495e4d408
treeb5c00024bd55192be70473552c4d4707d286d421
parent2e1c12409662c20f45b0e4dabaadff033ef674f7
libstdc++: fix element construction in std::deque::emplace [PR118087]

In order to emplace a value in the middle of a deque, a temporary was
previously constructed directly with __args... in _M_emplace_aux.
This would not work since std::deque is allocator-aware and should
construct elements with _Alloc_traits::construct instead before the
element is moved.

Using the suggestion in PR118087, we can define _Temporary_value
similar to the one used in std::vector, so the temporary can be
constructed with uses-allocator construction.

PR libstdc++/118087

libstdc++-v3/ChangeLog:

* include/bits/deque.tcc: Use _Temporary_value in
_M_emplace_aux.
* include/bits/stl_deque.h: Introduce _Temporary_value.
* testsuite/23_containers/deque/modifiers/emplace/118087.cc:
New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Ben Wu <soggysocks206@gmail.com>
libstdc++-v3/include/bits/deque.tcc
libstdc++-v3/include/bits/stl_deque.h
libstdc++-v3/testsuite/23_containers/deque/modifiers/emplace/118087.cc [new file with mode: 0644]