From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3F7893858C83; Thu, 26 Jan 2023 10:14:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F7893858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674728093; bh=Ggz+Dgppnb5N4sCaEp4qcUMrVyhukfJv3lpuXgincec=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LUWsC7cnPShFBnbQemJ7MVjwmiB8RRUc8GznrLHhxYsxJv5Wi3f5g+45Ued/P6Pm1 jyPsaR9foP62pUhNVi77e+aH4SLp69KulRYlBttBZgXz4J5FNhGx1HC77ywSEobif3 bW/uy9vGJZPLQnS3aoNOW9U1f5HTWIh/WpDIDDkI= From: "redi 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 10:14: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: 12.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi 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 #4 from Jonathan Wakely --- (In reply to Jan de Cuveland from comment #2) > So it is just that the static analyzer does not see that (to my > understanding) "it" has to be a valid iterator and thus will always result > in a non-empty node handle. I thought that was the case, but it's actually a little more complicated. T= here are some non-inline functions used by std::map when rebalancing the tree, a= nd the compiler doesn't know that they never return a null pointer (assuming v= alid inputs, i.e. no past-the-end iterators, which is a precondition of those functions anyway). The patch above uses the returns_nonnull attribute so the compiler knows th= at we always get a valid pointer back from those functions.=