https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103534
Bug ID: 103534 Summary: [12 regression] Spurious -Wstringop-overflow warning with std::string concatencation Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: s...@li-snyder.org Target Milestone: --- hi - With a recent checkout of gcc12 (20211201) on a x86_64-pc-linux-gnu host, compiling the following source with -O --std=c++20 gives a bogus -Wstringop-overflow warning: -- x.cc --------------------------------------------------- #include <string> std::string foo() { return std::string("1234567890123456") + std::string(""); } ----------------------------------------------------------- $ g++ -c -O --std=c++20 x.cc In file included from /usr/local/gcc/include/c++/12.0.0/string:40, from x.cc:1: In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(std::char_traits<char>::char_type*, const std::char_traits<char>::char_type*, std::size_t)’, inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:423:21, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_append(const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.tcc:417:19, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:1385:25, inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:3530:23, inlined from ‘std::string foo()’ at x.cc:5:59: /usr/local/gcc/include/c++/12.0.0/bits/char_traits.h:426:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound between 18446744073709551600 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] 426 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ $ Perhaps interestingly, the warning goes away if the first string literal is less than 16 characters long.