From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A1E32385141D; Mon, 28 Dec 2020 18:36:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1E32385141D From: "romain.geissler at amadeus dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98465] New: Bogus warning stringop-overread wuth -std=gnu++20 -O2 and std::string::insert Date: Mon, 28 Dec 2020 18:36:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: romain.geissler at amadeus dot com 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: Mon, 28 Dec 2020 18:36:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 Bug ID: 98465 Summary: Bogus warning stringop-overread wuth -std=3Dgnu++20 -O2 and std::string::insert Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: romain.geissler at amadeus dot com Target Milestone: --- Hi, The following C++ code compiled with -std=3Dgnu++20 -O2 -Werror=3Dstringop-= overread emits a bogus warning/error with gcc trunk, while it works without problem = when using gnu++17 instead. Tested on compiler explorer on x64 Linux: #include const char constantString[] =3D {42, 53}; void f(std::string& s) { s.insert(0, static_cast(constantString), 2); } In file included from /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/string:40, from :1: In static member function 'static constexpr std::char_traits::char_ty= pe* std::char_traits::copy(std::char_traits::char_type*, const char_type*, std::size_t)', inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_str= ing.h:351:21, inlined from 'static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_str= ing.h:346:7, inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*, std::__cxx11::basic_string<_CharT, _Trai= ts, _Alloc>::size_type) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_str= ing.tcc:481:20, inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*, std::__cxx11::basic_string<_CharT, _Trai= ts, _Alloc>::size_type) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_str= ing.h:1946:19, inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_t= ype, const _CharT*, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_ty= pe) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]' at /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/basic_str= ing.h:1693:29, inlined from 'void f(std::string&)' at :7:60: /opt/compiler-explorer/gcc-trunk-20201228/include/c++/11.0.0/bits/char_trai= ts.h:402:56: error: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' read= ing 2 bytes from a region of size 0 [-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 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ : In function 'void f(std::string&)': :3:12: note: at offset 2 into source object 'constantString' of siz= e 2 3 | const char constantString[] =3D {42, 53}; | ^~~~~~~~~~~~~~ cc1plus: some warnings being treated as errors Compiler returned: 1 Note that gcc 10 doesn't issue any warning even with -Wall -Wextra with gnu++20. Cheers, Romain=