https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87576
--- Comment #1 from Tom Mason <wheybags at wheybags dot com> --- Trying to compile the attached source file leads to gcc generating a memcpy out of the loop on line 134, then erroring because the generated memcpy overlaps. Indeed the regions do overlap, so if that is a problem, it should not replace the loop with a memcpy. It also generates a max object size exceeded error, which I don't understand? $ ~/gcc-8/bin/g++-8 -O3 -g -DDEBUG -D_DEBUG -Wno-array-bounds -Wall -Wextra -pedantic -Wno-unused-parameter -Werror -std=c++17 main.cpp In function ‘int main(int, char**)’: cc1plus: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551592 or more bytes at offsets 12 and 24 overlaps 9223372036854775761 bytes at offset -9223372036854775785 [-Werror=restrict] cc1plus: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified size between 18446744073709551592 and 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=] cc1plus: all warnings being treated as errors Without -Wno-array-bounds, it will generate an out of bounds access error instead. This is another issue, as the branch containing this loop is never taken, so the out of bounds error should not be generated. [tom-debian] ~/test_scripts/gcc_bug > $ ~/gcc-8/bin/g++-8 -O3 -g -DDEBUG -D_DEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Werror -std=c++17 main.cpp main.cpp: In function ‘int main(int, char**)’: main.cpp:135:76: error: array subscript 6 is above array bounds of ‘int [5]’ [-Werror=array-bounds] this->smallData.arr[first + offset] = std::move(this->smallData.arr[last + offset]); ~~~~~~~~~~~~~~~~~~~^ cc1plus: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ pointer overflow between offset 12 and size [-24, 9223372036854775807] [-Werror=array-bounds] cc1plus: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified size between 18446744073709551592 and 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=] cc1plus: all warnings being treated as errors