public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/105705] New: std::equal triggers incorrect -Wnonnull warning
@ 2022-05-23 19:04 derek.mauro at gmail dot com
  2022-05-23 19:11 ` [Bug tree-optimization/105705] [12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: derek.mauro at gmail dot com @ 2022-05-23 19:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105705

            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 first 2
arguments and v1 for the second set) does not trigger the bug.

#include <vector>
#include <algorithm>

bool f() {
  std::vector<int> v0;
  std::vector<int> 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) [with
_Tp = int; _Up = int]',
    inlined from 'static bool std::__equal<true>::equal(const _Tp*, const _Tp*,
const _Tp*) [with _Tp = 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 = int*;
_II2 = int*]' at /usr/local/include/c++/12.1.0/bits/stl_algobase.h:1210:43,
    inlined from 'bool std::__equal_aux(_II1, _II1, _II2) [with _II1 =
__gnu_cxx::__normal_iterator<int*, vector<int> >; _II2 =
__gnu_cxx::__normal_iterator<int*, vector<int> >]' at
/usr/local/include/c++/12.1.0/bits/stl_algobase.h:1218:31,
    inlined from 'bool std::equal(_II1, _II1, _II2) [with _II1 =
__gnu_cxx::__normal_iterator<int*, vector<int> >; _II2 =
__gnu_cxx::__normal_iterator<int*, vector<int> >]' 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 =
__gnu_cxx::__normal_iterator<int*, vector<int> >; _II2 =
__gnu_cxx::__normal_iterator<int*, vector<int> >]' 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 =
__gnu_cxx::__normal_iterator<int*, vector<int> >; _II2 =
__gnu_cxx::__normal_iterator<int*, vector<int> >]' 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);
      |               
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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 unsigned
int)'

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-08 12:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 19:04 [Bug libstdc++/105705] New: std::equal triggers incorrect -Wnonnull warning derek.mauro at gmail dot com
2022-05-23 19:11 ` [Bug tree-optimization/105705] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-05-24  7:23 ` rguenth at gcc dot gnu.org
2022-05-24  7:30 ` jakub at gcc dot gnu.org
2022-05-24  7:40 ` jakub at gcc dot gnu.org
2022-05-24  8:53 ` redi at gcc dot gnu.org
2022-05-24  8:58 ` redi at gcc dot gnu.org
2022-05-24  9:37 ` rguenther at suse dot de
2023-05-08 12:24 ` [Bug tree-optimization/105705] [12/13/14 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).