From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F380D3858433; Thu, 26 Jan 2023 13:38:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F380D3858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674740318; bh=SPARyW24CSdtdgXyqdllSmrmv+vCGoRZn9caC8friiQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ANAL7pgH1YqA38Em0+AYaUUbSfgD0VDd19aPh4ImsRuKpx2BT2BYkEl6RMZov/e7o /HeXAas80j1xgDYwfzyNYIVg7o9I6P00QHNWnEpsQ5AP9iNDBokl803rexXMvP0Qvp /2Ac1x9GPRCnNDedzl5KcKZylwCrxYoT3FrR9GNg= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108554] Warning "null pointer dereferece" raised when extracting a unique_ptr from a map and any "-O" flag Date: Thu, 26 Jan 2023 13:38:37 +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: 12.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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=3D108554 --- Comment #5 from CVS Commits --- The master branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:3376467ce090aa0966d59ca3aea35db4f17a4b47 commit r13-5386-g3376467ce090aa0966d59ca3aea35db4f17a4b47 Author: Jonathan Wakely Date: Thu Jan 26 10:55:28 2023 +0000 libstdc++: Add returns_nonnull to non-inline std::map detail [PR108554] std::map uses a non-inline function to rebalance its tree and the compiler can't see that it always returns a valid pointer (assuming valid inputs, which is a precondition anyway). This can result in -Wnull-derefernce warnings for valid code, because the compiler thinks there is a path where the function returns null. Adding the returns_nonnull attribute tells the compiler that is can't happen. While we're doing that, we might as well also add a nonnull attribute to the rebalancing functions too. libstdc++-v3/ChangeLog: PR libstdc++/108554 * include/bits/stl_tree.h (_Rb_tree_insert_and_rebalance): Add nonnull attribute. (_Rb_tree_rebalance_for_erase): Add nonnull and returns_nonnull attributes. * testsuite/23_containers/map/modifiers/108554.cc: New test.=