https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104017
Lars Gullik Bjønnes <larsbj at gullik dot net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |larsbj at gullik dot net --- Comment #2 from Lars Gullik Bjønnes <larsbj at gullik dot net> --- (In reply to Martin Sebor from comment #1) ... > #include <deque> > > struct Node { Node const * parent = nullptr; }; > > void func(Node const * n) > { > std::deque<Node const *> p; > > Node const * e = n; > > while (e != nullptr) { > p.push_front(e); > e = e->parent; > } > > if (p.size ()) > p.pop_front(); > if (p.size ()) > p.pop_front(); > if (p.size ()) > p.pop_back(); > } > > > 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). This is also the case amended with a check that the std::deque::size is large enough (for the same reason). In that case the crash can never happen, still GCC12 warns/errors. I agree that the first test case, and the warning from it, is helpful. However this second one not so much.