[Bug libstdc++/105705] New: std::equal triggers incorrect -Wnonnull warning
derek.mauro at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon May 23 19:04:05 GMT 2022
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)'
More information about the Gcc-bugs
mailing list