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 libstdc++/108517] std::sort of empty range yield "warning: 'this' pointer is null"
Date: Tue, 24 Jan 2023 12:33:52 +0000	[thread overview]
Message-ID: <bug-108517-4-YXjZrE0JIk@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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-01-24
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please provide the code here instead of just a link, as per
https://gcc.gnu.org/bugs/

#include <algorithm>

struct object {
    size_t size() const noexcept;
};

struct empty_vec {
    object * begin() noexcept {
        return nullptr;
    }
    object * end() noexcept {
        return nullptr;
    }
};

int main() {
    auto sort_by_size = [](const auto & lhs, const auto & rhs) { return
lhs.size() < rhs.size(); };

    empty_vec vec{};
        std::sort(vec.begin(), vec.end(), sort_by_size);
}



$ g++ -O2 sort.cc -c -Wall 
In lambda function,
    inlined from 'constexpr bool
__gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2)
[with _Iterator1 = object*; _Iterator2 = object*; _Compare =
main()::<lambda(const auto:1&, const auto:2&)>]' at
/usr/include/c++/12/bits/predefined_ops.h:158:30,
    inlined from 'void std::__insertion_sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = object*;
_Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const auto:1&,
const auto:2&)> >]' at /usr/include/c++/12/bits/stl_algo.h:1809:14:
sort.cc:17:94: warning: 'this' pointer is null [-Wnonnull]
   17 |     auto sort_by_size = [](const auto & lhs, const auto & rhs) { return
lhs.size() < rhs.size(); };
      |                                                                        
             ~~~~~~~~^~
sort.cc: In function 'void std::__insertion_sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = object*;
_Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const auto:1&,
const auto:2&)> >]':
sort.cc:4:12: note: in a call to non-static member function 'size_t
object::size() const'
    4 |     size_t size() const noexcept;
      |            ^~~~
In file included from /usr/include/c++/12/algorithm:60,
                 from sort.cc:1:
In static member function 'static _Tp* std::__copy_move_backward<_IsMove, true,
std::random_access_iterator_tag>::__copy_move_b(const _Tp*, const _Tp*, _Tp*)
[with _Tp = object; bool _IsMove = true]',
    inlined from '_BI2 std::__copy_move_backward_a2(_BI1, _BI1, _BI2) [with
bool _IsMove = true; _BI1 = object*; _BI2 = object*]' at
/usr/include/c++/12/bits/stl_algobase.h:760:37,
    inlined from '_BI2 std::__copy_move_backward_a1(_BI1, _BI1, _BI2) [with
bool _IsMove = true; _BI1 = object*; _BI2 = object*]' at
/usr/include/c++/12/bits/stl_algobase.h:769:51,
    inlined from '_OI std::__copy_move_backward_a(_II, _II, _OI) [with bool
_IsMove = true; _II = object*; _OI = object*]' at
/usr/include/c++/12/bits/stl_algobase.h:798:31,
    inlined from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 =
object*; _BI2 = object*]' at /usr/include/c++/12/bits/stl_algobase.h:892:47,
    inlined from 'void std::__insertion_sort(_RandomAccessIterator,
_RandomAccessIterator, _Compare) [with _RandomAccessIterator = object*;
_Compare = __gnu_cxx::__ops::_Iter_comp_iter<main()::<lambda(const auto:1&,
const auto:2&)> >]' at /usr/include/c++/12/bits/stl_algo.h:1813:8:
/usr/include/c++/12/bits/stl_algobase.h:742:30: warning: argument 2 null where
non-null expected [-Wnonnull]
  742 |             __builtin_memmove(__result - _Num, __first, sizeof(_Tp) *
_Num);
      |            
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:742:30: note: in a call to built-in
function 'void* __builtin_memmove(void*, const void*, long unsigned int)'



This looks related to PR 105705. Before gcc-12 the warning was already present,
but only when using -Wsystem-headers

  reply	other threads:[~2023-01-24 12:33 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 ` redi at gcc dot gnu.org [this message]
2023-01-24 12:35 ` [Bug libstdc++/108517] " 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
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-YXjZrE0JIk@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).