https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110204
Bug ID: 110204 Summary: Suspicous warning when compiling ranges-v3 using GCC trunk (iteration 9223372036854775807 invokes undefined behavior) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jun at junz dot org Target Milestone: --- Given code: #include <vector> #include <map> #include <range/v3/all.hpp> std::map<int, int> m; std::vector<int> foo() { return ranges::to<std::vector>(m | ranges::views::keys); } GCC trunk reports: /opt/compiler-explorer/gcc-trunk-20230610/include/c++/14.0.0/bits/stl_iterator_base_funcs.h:175:9: warning: iteration 9223372036854775807 invokes undefined behavior [-Waggressive-loop-optimizations] 175 | while (__n--) | ^~~~~ /opt/compiler-explorer/gcc-trunk-20230610/include/c++/14.0.0/bits/stl_iterator_base_funcs.h:175:9: note: within this loop while Clang and GCC 13 both say OK. I think this is a regression. goldbolt link: https://godbolt.org/z/W33aMqr5c