From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 05A97385781A; Thu, 21 Apr 2022 07:41:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05A97385781A From: "boris at kolpackov dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105329] New: Bogus restrict warning when assigning 1-char string literal to std::string Date: Thu, 21 Apr 2022 07:41:57 +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: boris at kolpackov dot net 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, 21 Apr 2022 07:41:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105329 Bug ID: 105329 Summary: Bogus restrict warning when assigning 1-char string literal to std::string Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: boris at kolpackov dot net Target Milestone: --- When compiling my codebase (build2) with GCC 12 (12.0.1 20220421) the outpu= t is littered with new bogus (AFAICS) -Wrestrict warnings that seems to be trigg= ered by any attempt to assign or append a 1-char string literal to std::string: $ cat <bogus-restrict.cxx #include void f (std::string& s) { s =3D "5"; } EOF $ g++ -Wall -Wextra -O3 -c -std=3Dc++23 bogus-restrict.cxx In file included from /home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/12.0.1/s= tring:40, from bogus-restrict.cxx:1: In static member function =E2=80=98static constexpr std::char_traits:= :char_type* std::char_traits::copy(char_type*, const 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*, size_type) [with _CharT = =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]= =E2=80=99 at /home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/12.0.1/b= its/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_replace(size_type, size_type, const _CharT*, size_type) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99 at /home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/12.0.1/b= its/basic_string.tcc:532:22, inlined from =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Tra= its, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::assign(const _CharT*) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc = =3D std::allocator]=E2=80=99 at /home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/12.0.1/b= its/basic_string.h:1647:19, inlined from =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Tra= its, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=3D(c= onst _CharT*) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc = =3D std::allocator]=E2=80=99 at /home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/12.0.1/b= its/basic_string.h:815:28, inlined from =E2=80=98void f(std::string&)=E2=80=99 at bogus-restrict.c= xx:5:7: /home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/12.0.1/b= its/char_traits.h:431:56: warning: =E2=80=98void* __builtin_memcpy(void*, const void*, long unsigned = int)=E2=80=99 accessing 9223372036854775810 or more bytes at offsets -4611686018427387902= and [-4611686018427387903, 4611686018427387904] may overlap up to 9223372036854775813 bytes at offset -3 [-Wrestrict] 431 | return static_cast(__builtin_memcpy(__s1, __s2, __n)); |=