public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "derek.mauro at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-105705-4@http.gcc.gnu.org/bugzilla/> (raw)

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)'

             reply	other threads:[~2022-05-23 19:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 19:04 derek.mauro at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105705-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).