From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 811E63858D28; Thu, 26 Jan 2023 09:13:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 811E63858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674724416; bh=J0oemyhLwH+vmL7HArrk2pxCDTlL9nPSPb/qB4NBwPQ=; h=From:To:Subject:Date:From; b=GDI41aXK6c7NXDnbzIWKwyraXimSn9OM/DvUQPRch9NBh8AEJN3ynHhUG+kZety93 mX57+cmxAb+Av2yQXacKsIw0yI0IKYhqI0nJ/tnmbDvjtGDZwvnN4EPFXftnZhfwwx 27C3b3Sgk3KGeMR0mFkYjFrET+dE5riwBa5L1KY4= From: "fcontact at cuveland dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108554] New: Warning "null pointer dereferece" raised when extracting a unique_ptr from a map and any "-O" flag Date: Thu, 26 Jan 2023 09:13:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fcontact at cuveland dot de X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 Bug ID: 108554 Summary: Warning "null pointer dereferece" raised when extracting a unique_ptr from a map and any "-O" flag Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: fcontact at cuveland dot de Target Milestone: --- I found what I believe might be a false positive with g++ 12 when using the "-Wnull-dereference" warning and a map of unique_ptr with any level of optimisation. This behavior does not show up in GCC 9, 10, and 11. Small but complete example: #include #include #include #include int main() { // create and initialize a map std::map> my_map; my_map["my_key"] =3D std::make_unique(1); auto it =3D my_map.find("my_key"); if (it !=3D my_map.end()) { // extract an item from the map auto item =3D std::move(my_map.extract(it).mapped()); return *item; } return 0; } Compiled with: g++-12 -O -Wnull-dereference Compiler version: g++ (Compiler-Explorer-Build-gcc--binutils-2.38) 12.2.0 (see https://godbolt.org/z/E9KhTT4f6)=