From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 96519385841A; Thu, 2 Dec 2021 19:47:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96519385841A From: "sss@li-snyder.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103534] New: [12 regression] Spurious -Wstringop-overflow warning with std::string concatencation Date: Thu, 02 Dec 2021 19:47:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sss@li-snyder.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Dec 2021 19:47:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103534 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: sss@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=3Dc++20 gives a bogus -Wstringop-overflow warning: -- x.cc --------------------------------------------------- #include std::string foo() { return std::string("1234567890123456") + std::string(""); } ----------------------------------------------------------- $ g++ -c -O --std=3Dc++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 =E2=80=98static constexpr std::char_traits:= :char_type* std::char_traits::copy(std::char_traits::char_type*, const std::char_traits::char_type*, std::size_t)=E2=80=99, inlined from =E2=80=98static constexpr void std::__cxx11::basic_string<= _CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _Char= T =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]= =E2=80=99 at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:423:21, inlined from =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Tra= its, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_append(const _CharT*, std::__cxx11::basic_string<_CharT, _Trait= s, _Alloc>::size_type) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99 at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.tcc:417:19, inlined from =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Tra= its, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::append(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80= =99 at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:1385:25, inlined from =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Tra= its, _Allocator> std::operator+(std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [= with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99 at /usr/local/gcc/include/c++/12.0.0/bits/basic_string.h:3530:23, inlined from =E2=80=98std::string foo()=E2=80=99 at x.cc:5:59: /usr/local/gcc/include/c++/12.0.0/bits/char_traits.h:426:56: warning: =E2= =80=98void* __builtin_memcpy(void*, const void*, long unsigned int)=E2=80=99 specified = bound between 18446744073709551600 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=3D] 426 | return static_cast(__builtin_memcpy(__s1, __s2, __n)); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ $=20 Perhaps interestingly, the warning goes away if the first string literal is less than 16 characters long.=