From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B28EC3858CDA; Thu, 14 Sep 2023 13:14:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B28EC3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694697261; bh=Ry9xJSeU8qNZjbkPMyEOdMqSu7k6KLWHocHZP+zxNWA=; h=From:To:Subject:Date:From; b=qR8WzIEUY7Hoqlp2QegM3dmqw+zg7FYL5wK+938v8c4K+eUEv5Wkiur3tWrDlRYKo 3MpWqUN066sqS7HKjbsxrvup/37cKeUzuy3sSG8kCItNzYwMczCwwdMRIITMPqCWrv yNsV8LbLeAqzm7lR09y6pS+yz0ftyrHblAjKzBfk= From: "daiw at gmx dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111415] New: False positive array-bounds warning with -O3 Date: Thu, 14 Sep 2023 13:14:21 +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: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daiw at gmx 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111415 Bug ID: 111415 Summary: False positive array-bounds warning with -O3 Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: daiw at gmx dot net Target Milestone: --- Using g++ (GCC) 13.2.0, the following minimal example: std::vector foo(const std::vector& a) { if (a.size() < 2) { return a; } return a; } int main() { foo(std::vector({1})); } Produces a warning when trying to compile like so: g++ -Wall -O3 main.cpp Output: In file included from /usr/local/include/c++/13.2.0/vector:62, from main.cpp:1: In static member function 'static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp =3D = const int; _Up =3D int; bool _IsMove =3D false]', inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove= =3D false; _II =3D const int*; _OI =3D int*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:506:30, inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove= =3D false; _II =3D const int*; _OI =3D int*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:533:42, inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = =3D false; _II =3D __gnu_cxx::__normal_iterator >; _OI = =3D int*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:540:31, inlined from '_OI std::copy(_II, _II, _OI) [with _II =3D __gnu_cxx::__normal_iterator >; _OI =3D int*]' at /usr/local/include/c++/13.2.0/bits/stl_algobase.h:633:7, inlined from 'static _ForwardIterator std::__uninitialized_copy::__uninit_copy(_InputIterator, _InputIterat= or, _ForwardIterator) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _ForwardIterator =3D int*]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:147:27, inlined from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _ForwardIterator =3D int*]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:185:15, inlined from '_ForwardIterator std::__uninitialized_copy_a(_InputIterat= or, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator =3D __gnu_cxx::__normal_iterator >; _ForwardIterator =3D int*; _Tp =3D int]' at /usr/local/include/c++/13.2.0/bits/stl_uninitialized.h:373:37, inlined from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp =3D int; _Alloc =3D std::allocator]' at /usr/local/include/c++/13.2.0/bits/stl_vector.h:603:31, inlined from 'std::vector foo(const std::vector&)' at main.cpp:7:16: /usr/local/include/c++/13.2.0/bits/stl_algobase.h:437:30: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' forming offset 4 = is out of the bounds [0, 4] [-Warray-bounds=3D] 437 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num= ); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~=