https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104017
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #1)
> This test case also triggers a warning, for the same reason: GCC can't
> determine the relationship between a deque's internal node pointers and the
> result of std::deque::size() (which is a function of the node pointers).
Is the warning in this case coming from this function?
void
pop_back() _GLIBCXX_NOEXCEPT
{
__glibcxx_requires_nonempty();
if (this->_M_impl._M_finish._M_cur
!= this->_M_impl._M_finish._M_first)
{
--this->_M_impl._M_finish._M_cur;
_Alloc_traits::destroy(_M_get_Tp_allocator(),
this->_M_impl._M_finish._M_cur);
}
else
_M_pop_back_aux();
}
I don't see what size() has got to do with anything, we explicitly check that
_M_cur is not the start of the node.
With -D_GLIBCXX_ASSERTIONS the first line of the function expands to:
__glibcxx_assert(!this->empty())
but it still warns.
What else are we supposed to do there to let the compiler know the object we're
destroying is valid? Do we need to add a third way to check the deque is not
empty?