https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121280
--- Comment #3 from Ryan Stocks <ryan.stocks00 at gmail dot com> --- (In reply to Andrew Pinski from comment #1) > Note this code is undefined if vect.empty() is true due to front being > undefined in that case. > Adding that check makes the warning go away too; either for > `vect_copy.empty()`or `vect.empty()`. > > So this is definitely NOT a false positive (there is a missed optimization > with respect size()==0 case but that is fixed up later on). > > Also see https://gcc.gnu.org/pipermail/gcc-patches/2025-August/691467.html . Does this mean the first case is a false negative? (In reply to Andrew Pinski from comment #1) > Note this code is undefined if vect.empty() is true due to front being > undefined in that case. > Adding that check makes the warning go away too; either for > `vect_copy.empty()`or `vect.empty()`. > > So this is definitely NOT a false positive (there is a missed optimization > with respect size()==0 case but that is fixed up later on). > > Also see https://gcc.gnu.org/pipermail/gcc-patches/2025-August/691467.html . This code still has the warning despite enforcing that the vector is not empty such that (to the best of my understanding) there is no undefined behavior so this one is a false positive? ``` void vector_func(std::vector<int>& vect) { if (vect.size() > 0) { std::vector<int> vect_copy = vect; if (vect_copy.front() < vect_copy.back()) { vect_copy.front() = vect_copy.back(); } vect = vect_copy; } } ``` https://godbolt.org/z/MEGf75W8z