https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80472
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- Another place where I'd like to selectively enable warnings is for this code (from PR 78830): #include <forward_list> #include <algorithm> int main() { std::forward_list<int> il = {1, 2, 3, 4, 5, 6, 7}; auto iter = std::prev(il.end()); } With -Wall -O1 -Wsystem-headers GCC detects the undefined behaviour: In file included from /home/jwakely/gcc/9/include/c++/9.0.1/bits/stl_algobase.h:66, from /home/jwakely/gcc/9/include/c++/9.0.1/bits/forward_list.h:38, from /home/jwakely/gcc/9/include/c++/9.0.1/forward_list:38, from prev.cc:1: /home/jwakely/gcc/9/include/c++/9.0.1/bits/stl_iterator_base_funcs.h:153:7: warning: iteration 9223372036854775807 invokes undefined behavior [-Waggressive-loop-optimizations] 153 | while (__n--) | ^~~~~ /home/jwakely/gcc/9/include/c++/9.0.1/bits/stl_iterator_base_funcs.h:153:7: note: within this loop but that very useful warning is suppressed by default. This bug prevents me from locally enabling -Wsystem-headers around the relevant functions in <bits/stl_iterator_base_funcs.h>.