https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101361
--- Comment #13 from Taiju Tsuiki <mail+gnu at tzik dot jp> --- I saw a similar inaccurate -Wstringop-overread warning with a smaller reproducer (attached). https://wandbox.org/permlink/EPjH0ZPoA4EWky0e Reproducing gcc was tip of trunk ( https://github.com/gcc-mirror/gcc/commits/33fb1625992ba8180b42988e714460bcab08ca0f ), and compile options and the error were: $ g++ -Werror -O3 -std=c++20 -c foo.cc In function ‘auto operator<=>(const V&, const V&)’, inlined from ‘Node* foo(Node*, const V&)’ at minify2/foo.cc:33:17: minify2/foo.cc:20:36: error: ‘int __builtin_memcmp(const void*, const void*, long unsigned int)’ specified bound [9223372036854775808, 18446744073709551615] exceeds maximum object size 9223372036854775807 (9) [-Werror=stringop-overread] 20 | const auto c = __builtin_memcmp(x.beg, y.beg, len) <=> 0; | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ minify2/foo.cc:17:15: note: source object allocated here 17 | }(x.end - x.beg, y.end - y.beg); | ~~^~~ $ cat foo.cc #include <compare> struct Res { long min; std::strong_ordering cmp; }; struct V { const unsigned char* beg = nullptr; const unsigned char* end = nullptr; }; auto operator<=>(const V& x, const V& y) { const auto [len, lencmp] = [&](long len_x, long len_y) { auto c = len_x <=> len_y; return Res{c > 0 ? len_y : len_x, c}; }(x.end - x.beg, y.end - y.beg); if (len) { const auto c = __builtin_memcmp(x.beg, y.beg, len) <=> 0; if (c != 0) return c; } return lencmp; } struct Node { Node* next = nullptr; V v; }; Node* foo(Node* x, const V& k) { while (x && k < x->v) x = x->next; return x; }