From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3512385700F; Wed, 30 Dec 2020 13:22:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3512385700F From: "romain.geissler at amadeus dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98465] Bogus warning stringop-overread wuth -std=gnu++20 -O2 and std::string::insert Date: Wed, 30 Dec 2020 13:22:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: romain.geissler at amadeus dot com X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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: Wed, 30 Dec 2020 13:22:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 --- Comment #3 from Romain Geissler --- I have found another example in my code base raising this error: #include std::string f1() { std::string aString =3D "string"; aString =3D "bigger str"; return aString; } With: -O2 -std=3Dgnu++20 -Werror=3Dstringop-overread -Wno-system-headers -g raises: /opt/compiler-explorer/gcc-trunk-20201230/include/c++/11.0.0/bits/char_trai= ts.h:402:56: error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' read= ing 10 bytes from a region of size 7 [-Werror=3Dstringop-overread] 402 | 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 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ Yet now what confuses me is that if I add copy of this function later using bigger strings (so not exposing the bug), the new f2 function makes the war= ning disappear form the f1 function: #include std::string f1() { std::string aString =3D "string"; aString =3D "bigger str"; // <--- no more warning here when we have fun= ction f2 ! return aString; } std::string f2() { std::string aString =3D "initial string with enough capacity"; aString =3D "smaller str"; return aString; } Why does having a function f2 affects warnings in function f1 ?=