From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 74083385771F; Fri, 14 Apr 2023 15:33:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74083385771F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681486417; bh=kU9U6ApZogW0g/ZY3nVFGLMzv5sDhZX5F7Eb1dBQxh4=; h=From:To:Subject:Date:From; b=jpVo+X4DjzZrMFCFkRiRdP2CYMKpPnY4ewbVJx/3kEzO6u4ik5u0CC5elK0qvKHJi HoV7rN+ARjuwSi26WxVUIIyk76QTc+LVVKUNPs+YfmmYrE4k/T2qeajdv29caO8BEa DBdessMkAfOvmGPS7shjT25tpwsv9yEHF0QfrG7U= From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109514] New: [13 regression] -Werror=dangling-pointer false positive nn fheroes-1.0.3 (lambdas) Date: Fri, 14 Apr 2023 15:33:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: slyfox at gcc dot gnu.org 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=3D109514 Bug ID: 109514 Summary: [13 regression] -Werror=3Ddangling-pointer false positive nn fheroes-1.0.3 (lambdas) Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org Target Milestone: --- Initially noticed the false positive on fheroes2-1.0.3 project which uses -Werror by default. Here is the extracted example: // $ cat screen.cpp #include #include struct R { int w; }; typedef std::vector vr_t; typedef std::set sr_t; static sr_t FilterRs (const sr_t & rs) { return rs; } vr_t getRs () { const vr_t filteredRs =3D []() { sr_t rs; rs =3D FilterRs (rs); return vr_t{rs.begin(), rs.end()}; }(); return filteredRs; } $ g++ -c -O2 screen.cpp -Werror=3Ddangling-pointer In file included from /<>/gcc-13.0.0/include/c++/13.0.1/set:62, from screen.cpp:1: In member function 'void std::_Rb_tree_header::_M_move_data(std::_Rb_tree_header&)', inlined from 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_move_data(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, std::true_type) [with _Key =3D R; _Val =3D R; _KeyOfValue =3D std::_Identity; _Compare =3D std::less; _Alloc =3D std::allocator]= ' at /<>/gcc-13.0.0/include/c++/13.0.1/bits/stl_tree.h:1421:29, inlined from 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_move_assign(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, std::true_type) [with _Key =3D R; _Val =3D R; _KeyOfValue =3D std::_Identity; _Compare =3D std::less; _Alloc =3D std::allocator]= ' at /<>/gcc-13.0.0/include/c++/13.0.1/bits/stl_tree.h:1710:14, inlined from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::operator=3D(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Allo= c>&&) [with _Key =3D R; _Val =3D R; _KeyOfValue =3D std::_Identity; _Compare = =3D std::less; _Alloc =3D std::allocator]' at /<>/gcc-13.0.0/include/c++/13.0.1/bits/stl_tree.h:1744:21, inlined from 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=3D(std::set<_Key, _Compare, _Alloc>&&) [with _Key =3D R; = _Compare =3D std::less; _Alloc =3D std::allocator]' at /<>/gcc-13.0.0/include/c++/13.0.1/bits/stl_set.h:302:7, inlined from 'getRs()::' at screen.cpp:21:26, inlined from 'vr_t getRs()' at screen.cpp:24:7: /<>/gcc-13.0.0/include/c++/13.0.1/bits/stl_tree.h:199:38: error: stori= ng the address of local variable 'rs' in '*MEM[(struct _Rb_tree_node_base * &)&D.35566 + 16].std::_Rb_tree_node_base::_M_parent' [-Werror=3Ddangling-pointer=3D] 199 | _M_header._M_parent->_M_parent =3D &_M_header; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ screen.cpp: In function 'vr_t getRs()': screen.cpp:19:14: note: 'rs' declared here 19 | sr_t rs; | ^~ screen.cpp:19:14: note: '.std::set, std::allocator= >::_M_t.std::_Rb_tree, std::less, std::allocator= >::_M_impl.std::_Rb_tree, std::less, std::allocator >::_Rb_tree_impl, true>::.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_= M_parent' declared here cc1plus: some warnings being treated as errors I think it's a false positive (or maybe it exposes some NRVO bug?). $ g++ -v Using built-in specs. COLLECT_GCC=3D/<>/gcc-13.0.0/bin/g++ COLLECT_LTO_WRAPPER=3D/<>/gcc-13.0.0/libexec/gcc/x86_64-unknown-linux-= gnu/13.0.1/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.1 20230409 (experimental) (GCC)=