From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2CD1B3858D32; Mon, 23 May 2022 19:04:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CD1B3858D32 From: "derek.mauro at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/105705] New: std::equal triggers incorrect -Wnonnull warning Date: Mon, 23 May 2022 19:04:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: derek.mauro at gmail 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, 23 May 2022 19:04:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105705 Bug ID: 105705 Summary: std::equal triggers incorrect -Wnonnull warning Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: derek.mauro at gmail dot com Target Milestone: --- The following program triggers an incorrect -Wnonnull warning when compiled with gcc 12.1.0 (I used the Docker container from https://hub.docker.com/_/= gcc on Linux). Note that it seems both -Wnonnull and -O2 are required to trigger the bug. Also note that reversing the arguments to std::equal (using v0 for the firs= t 2 arguments and v1 for the second set) does not trigger the bug. #include #include bool f() { std::vector v0; std::vector v1{1}; return std::equal(v1.begin(), v1.end(), v0.begin(), v0.end()); } g++ test.cc -Wnonnull -O2 In file included from /usr/local/include/c++/12.1.0/vector:60, from test.cc:1: In function 'constexpr int std::__memcmp(const _Tp*, const _Up*, size_t) [w= ith _Tp =3D int; _Up =3D int]', inlined from 'static bool std::__equal::equal(const _Tp*, const _= Tp*, const _Tp*) [with _Tp =3D int]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1176:27, inlined from 'bool std::__equal_aux1(_II1, _II1, _II2) [with _II1 =3D i= nt*; _II2 =3D int*]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1210:4= 3, inlined from 'bool std::__equal_aux(_II1, _II1, _II2) [with _II1 =3D __gnu_cxx::__normal_iterator >; _II2 =3D __gnu_cxx::__normal_iterator >]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1218:31, inlined from 'bool std::equal(_II1, _II1, _II2) [with _II1 =3D __gnu_cxx::__normal_iterator >; _II2 =3D __gnu_cxx::__normal_iterator >]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1555:30, inlined from 'bool std::__equal4(_II1, _II1, _II2, _II2) [with _II1 =3D __gnu_cxx::__normal_iterator >; _II2 =3D __gnu_cxx::__normal_iterator >]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1607:32, inlined from 'bool std::equal(_II1, _II1, _II2, _II2) [with _II1 =3D __gnu_cxx::__normal_iterator >; _II2 =3D __gnu_cxx::__normal_iterator >]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1677:38, inlined from 'bool f()' at test.cc:7:20: /usr/local/include/c++/12.1.0/bits/stl_algobase.h:105:32: warning: argument= 2 null where non-null expected [-Wnonnull] 105 | return __builtin_memcmp(__first1, __first2, sizeof(_Tp) * __num); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/c++/12.1.0/bits/stl_algobase.h:105:32: note: in a call to built-in function 'int __builtin_memcmp(const void*, const void*, long unsi= gned int)'=