From: Jonathan Wakely Date: Thu, 27 Feb 2025 21:59:41 +0000 (+0000) Subject: libstdc++: Add assertions to std::list::pop_{front,back} X-Git-Tag: basepoints/gcc-16~1687 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4412e9bb73754a0c9668e80c4b8ee2fefffbbb04;p=thirdparty%2Fgcc.git libstdc++: Add assertions to std::list::pop_{front,back} The recently-approved Standard Library Hardening proposal (P3471R4) gives pop_front and pop_back member functions hardened preconditions, but std::list was missing assertions on them. Our other sequence containers do have assertions on those members. libstdc++-v3/ChangeLog: * include/bits/stl_list.h (list::pop_front, list::pop_back): Add non-empty assertions. Reviewed-by: Patrick Palka --- diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index f987d8b9d0a..82ccb50ff18 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -1784,7 +1784,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 */ void pop_front() _GLIBCXX_NOEXCEPT - { this->_M_erase(begin()); } + { + __glibcxx_requires_nonempty(); + this->_M_erase(begin()); + } /** * @brief Add data to the end of the %list. @@ -1833,7 +1836,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 */ void pop_back() _GLIBCXX_NOEXCEPT - { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); } + { + __glibcxx_requires_nonempty(); + this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); + } #if __cplusplus >= 201103L /**