https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109205

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-03-20
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I guess we might as well do it for capacity too:

--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
@@ -985,7 +985,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
       size_type
       size() const _GLIBCXX_NOEXCEPT
-      { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
+      {
+       if (this->_M_impl._M_finish < this->_M_impl._M_start)
+         __builtin_unreachable();
+       return size_type(this->_M_impl._M_finish - this->_M_impl._M_start);
+      }

       /**  Returns the size() of the largest possible %vector.  */
       _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
@@ -1071,8 +1075,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
       size_type
       capacity() const _GLIBCXX_NOEXCEPT
-      { return size_type(this->_M_impl._M_end_of_storage
-                        - this->_M_impl._M_start); }
+      {
+       if (this->_M_impl._M_end_of_storage < this->_M_impl._M_start)
+         __builtin_unreachable();
+       return size_type(this->_M_impl._M_end_of_storage
+                        - this->_M_impl._M_start);
+      }

       /**
        *  Returns true if the %vector is empty.  (Thus begin() would

Reply via email to