From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 27DA33858D28; Tue, 24 Jan 2023 12:33:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27DA33858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674563633; bh=NYK3rifqOA8sTmhCVOdwy1g912QzOt75MvIw2ktttTI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Yjcx7ELCaKuaEWU90MrFcfSqRTXVk+wR7mvWCcVlf4Q5UFn1VKFl54mcfoXOuAe13 ahrFZzihy0XUqmJ6H2n1CWQhs4VnWaXOefsbAghDhcrExaNla/g2m4pG3jlpumj5zz 4lAU24be2fwS9ZDXk2uLvrnK8sFQ/CHeOIsQwyHA= From: "redi at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on bug_status everconfirmed keywords Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108517 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-01-24 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Keywords| |diagnostic --- Comment #1 from Jonathan Wakely --- Please provide the code here instead of just a link, as per https://gcc.gnu.org/bugs/ #include 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 =3D [](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=20 In lambda function, inlined from 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterat= or2) [with _Iterator1 =3D object*; _Iterator2 =3D object*; _Compare =3D main()::]' at /usr/include/c++/12/bits/predefined_ops.h:158:30, inlined from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator =3D object*; _Compare =3D __gnu_cxx::__ops::_Iter_comp_iter >]' 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 =3D [](const auto & lhs, const auto & rhs) { = return lhs.size() < rhs.size(); }; |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~^~ sort.cc: In function 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator =3D object*; _Compare =3D __gnu_cxx::__ops::_Iter_comp_iter >]': 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, t= rue, std::random_access_iterator_tag>::__copy_move_b(const _Tp*, const _Tp*, _Tp= *) [with _Tp =3D object; bool _IsMove =3D true]', inlined from '_BI2 std::__copy_move_backward_a2(_BI1, _BI1, _BI2) [with bool _IsMove =3D true; _BI1 =3D object*; _BI2 =3D 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 =3D true; _BI1 =3D object*; _BI2 =3D 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 =3D true; _II =3D object*; _OI =3D object*]' at /usr/include/c++/12/bits/stl_algobase.h:798:31, inlined from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 =3D object*; _BI2 =3D object*]' at /usr/include/c++/12/bits/stl_algobase.h:892:= 47, inlined from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator =3D object*; _Compare =3D __gnu_cxx::__ops::_Iter_comp_iter >]' 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 wh= ere non-null expected [-Wnonnull] 742 | __builtin_memmove(__result - _Num, __first, sizeof(_Tp)= * _Num); |=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /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 pres= ent, but only when using -Wsystem-headers=