https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78448
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- UBsan shows where the overflows happen: /home/jwakely/gcc/9/include/c++/9.0.0/bits/stl_vector.h:359:59: runtime error: pointer index expression with base 0x6760f010 overflowed to 0xf760f010 /home/jwakely/gcc/9/include/c++/9.0.0/bits/stl_algobase.h:777:20: runtime error: pointer index expression with base 0x6760f010 overflowed to 0xf760f010 /home/jwakely/gcc/9/include/c++/9.0.0/bits/stl_algobase.h:778:24: runtime error: pointer index expression with base 0x6760f010 overflowed to 0xf760f010 Vector maximal size: 4294967295 and actual size: 2415919104 Found value 2 We just need to fix our max_size() as per comment 0.