public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/108517] std::sort of empty range yield "warning: 'this' pointer is null"
Date: Tue, 24 Jan 2023 12:41:59 +0000	[thread overview]
Message-ID: <bug-108517-4-OhfhBIBYTv@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108517-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Libstdc++ isn't causing it, but we can give the compiler enough information to
make it shut up:

--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -1814,6 +1814,10 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
     {
       if (__first == __last) return;

+      if (__first == _RandomAccessIterator()
+            || __last == _RandomAccessIterator())
+        __builtin_unreachable();
+
       for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
        {
          if (__comp(__i, __first))


As you can see there, we already return early and never reach line 1819 where
the dereference happens. We can tell the compiler that it's impossible to get
to that that dereference with a value-initialized iterator, because if one is
null the other must be, and so we'd already have returned.

  parent reply	other threads:[~2023-01-24 12:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 12:01 [Bug libstdc++/108517] New: " hanicka at hanicka dot net
2023-01-24 12:33 ` [Bug libstdc++/108517] " redi at gcc dot gnu.org
2023-01-24 12:35 ` redi at gcc dot gnu.org
2023-01-24 12:37 ` [Bug c++/108517] " redi at gcc dot gnu.org
2023-01-24 12:41 ` redi at gcc dot gnu.org [this message]
2023-01-24 13:01 ` [Bug c++/108517] [11/12/13 Regression] " redi at gcc dot gnu.org
2023-01-24 13:07 ` rguenth at gcc dot gnu.org
2023-02-01 12:32 ` jakub at gcc dot gnu.org
2023-02-01 12:40 ` jakub at gcc dot gnu.org
2023-02-15 15:28 ` jamborm at gcc dot gnu.org
2023-02-21 12:59 ` rguenth at gcc dot gnu.org
2023-05-29 10:07 ` [Bug c++/108517] [11/12/13/14 " jakub 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-108517-4-OhfhBIBYTv@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).