From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 21813385802D; Tue, 30 Nov 2021 04:27:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21813385802D From: "john at mcfarlane dot name" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103483] New: constexpr basic_string triggers stringop-overread Date: Tue, 30 Nov 2021 04:27:56 +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: john at mcfarlane dot name 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: Tue, 30 Nov 2021 04:27:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103483 Bug ID: 103483 Summary: constexpr basic_string triggers stringop-overread Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: john at mcfarlane dot name Target Milestone: --- As of 9a27acc30a34b7854db32eac562306cebac6fa1e, "Make full use of context-sensitive ranges in access warnings.", this source.cpp #include template void c(int d) { char buffer[a] =3D {}; std::string(buffer, buffer+d); } int main() { c<1>(1); } with command line: `~/gcc-head/bin/g++ -Werror=3Dstringop-overread -O1 -std= =3Dc++20 source.cpp` emits: /home/john/ws/wide/cnl/build/source.cpp In file included from /home/john/gcc-head/include/c++/12.0.0/string:40, from /home/john/ws/wide/cnl/build/source.cpp: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 void std::__cxx11::basic_string<_CharT, _T= raits, _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]=E2=80=99 at /home/john/gcc-head/include/c++/12.0.0/bits/basic_string.h:361:21, inlined from =E2=80=98static void std::__cxx11::basic_string<_CharT, _T= raits, _Alloc>::_S_copy_chars(_CharT*, _CharT*, _CharT*) [with _CharT =3D char; _T= raits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99 at /home/john/gcc-head/include/c++/12.0.0/bits/basic_string.h:403:16, inlined from =E2=80=98void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator, std::forward_iterator_tag) [with _FwdIterator =3D char*; _CharT =3D char; _Traits =3D std::char_traits= ; _Alloc =3D std::allocator]=E2=80=99 at /home/john/gcc-head/include/c++/12.0.0/bits/basic_string.tcc:225:25, inlined from =E2=80=98void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct_aux(_InIterator, _InIterator, std::__false_type) [with _InIterator =3D char*; _CharT =3D char; _Traits =3D std::char_traits;= _Alloc =3D std::allocator]=E2=80=99 at /home/john/gcc-head/include/c++/12.0.0/bits/basic_string.h:257:23, inlined from =E2=80=98void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator) [with _InIterator =3D char*; _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99 at /home/john/gcc-head/include/c++/12.0.0/bits/basic_string.h:276:20, inlined from =E2=80=98std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator =3D char*; =3D void; _CharT =3D cha= r; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99 at /home/john/gcc-head/include/c++/12.0.0/bits/basic_string.h:645:16, inlined from =E2=80=98void c(int) [with int a =3D 1]=E2=80=99 at /home/john/ws/wide/cnl/build/source.cpp:4:8: /home/john/gcc-head/include/c++/12.0.0/bits/char_traits.h:355:56: error: = =E2=80=98void* __builtin_memcpy(void*, const void*, long unsigned int)=E2=80=99 reading be= tween 2 and 2147483647 bytes from a region of size 1 [-Werror=3Dstringop-overread] 355 | 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 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /home/john/ws/wide/cnl/build/source.cpp: In function =E2=80=98void c(int) [= with int a =3D 1]=E2=80=99: /home/john/ws/wide/cnl/build/source.cpp:3:8: note: source object =E2=80=98b= uffer=E2=80=99 of size 1 3 | char buffer[a] =3D {}; | ^~~~~~ cc1plus: some warnings being treated as errors Still emitting this warning as of SHA 909b30a17e71253772d2cb174d0dae6d0b8c9= 401 Compiler Explorer: https://godbolt.org/z/n9cqarErc Also emits array-bounds warning with `-Wall -Wno-stringop-overread`. If this is a dupe of an 88443 issue, I'm not sure which one.=