aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-15 22:03:20 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-11-27 12:30:01 +0000
commite7aa614d7372b5d3cbcd2400838c80ef905ba381 (patch)
treeba07e153e2bd9467c0a83475bbb24516b497ec17
parent751f91be72d8b73a9dc71456f475268397330100 (diff)
downloadgcc-e7aa614d7372b5d3cbcd2400838c80ef905ba381.zip
gcc-e7aa614d7372b5d3cbcd2400838c80ef905ba381.tar.gz
gcc-e7aa614d7372b5d3cbcd2400838c80ef905ba381.tar.bz2
libstdc++: Add debug assertions to std::list and std::forward_list
While working on fancy pointer support for the linked lists I noticed they didn't have any debug assertions. This adds the obvious non-empty assertions to front() and back(). libstdc++-v3/ChangeLog: * include/bits/forward_list.h (forward_list::front): Add non-empty assertions. * include/bits/stl_list.h (list::front, list::back): Add non-empty assertions.
-rw-r--r--libstdc++-v3/include/bits/forward_list.h3
-rw-r--r--libstdc++-v3/include/bits/stl_list.h13
2 files changed, 14 insertions, 2 deletions
diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h
index ac1b359..f6d4e6b 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -42,6 +42,7 @@
#include <bits/allocator.h>
#include <ext/alloc_traits.h>
#include <ext/aligned_buffer.h>
+#include <debug/assertions.h>
#if __glibcxx_ranges_to_container // C++ >= 23
# include <bits/ranges_base.h> // ranges::begin, ranges::distance etc.
# include <bits/ranges_util.h> // ranges::subrange
@@ -950,6 +951,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
reference
front()
{
+ __glibcxx_requires_nonempty();
_Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
return *__front->_M_valptr();
}
@@ -962,6 +964,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const_reference
front() const
{
+ __glibcxx_requires_nonempty();
_Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
return *__front->_M_valptr();
}
diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h
index 3f92de4..df7f388 100644
--- a/libstdc++-v3/include/bits/stl_list.h
+++ b/libstdc++-v3/include/bits/stl_list.h
@@ -59,6 +59,7 @@
#include <bits/concept_check.h>
#include <ext/alloc_traits.h>
+#include <debug/assertions.h>
#if __cplusplus >= 201103L
#include <initializer_list>
#include <bits/allocated_ptr.h>
@@ -1271,7 +1272,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NODISCARD
reference
front() _GLIBCXX_NOEXCEPT
- { return *begin(); }
+ {
+ __glibcxx_requires_nonempty();
+ return *begin();
+ }
/**
* Returns a read-only (constant) reference to the data at the first
@@ -1280,7 +1284,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX_NODISCARD
const_reference
front() const _GLIBCXX_NOEXCEPT
- { return *begin(); }
+ {
+ __glibcxx_requires_nonempty();
+ return *begin();
+ }
/**
* Returns a read/write reference to the data at the last element
@@ -1290,6 +1297,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
reference
back() _GLIBCXX_NOEXCEPT
{
+ __glibcxx_requires_nonempty();
iterator __tmp = end();
--__tmp;
return *__tmp;
@@ -1303,6 +1311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
const_reference
back() const _GLIBCXX_NOEXCEPT
{
+ __glibcxx_requires_nonempty();
const_iterator __tmp = end();
--__tmp;
return *__tmp;