https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106238
Romain Geissler <romain.geissler at amadeus dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |romain.geissler at amadeus dot com --- Comment #5 from Romain Geissler <romain.geissler at amadeus dot com> --- Hi, This seems to still happen with current trunk: #include <map> std::map<int, int> _Map; void f() { std::map<int, int> localMap; _Map.swap(localMap); } compiled with -Wall -Werror -O2: In file included from /opt/compiler-explorer/gcc-trunk-20230108/include/c++/13.0.0/map:62, from <source>:1: In member function 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::swap(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&) [with _Key = int; _Val = std::pair<const int, int>; _KeyOfValue = std::_Select1st<std::pair<const int, int> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]', inlined from 'void std::map<_Key, _Tp, _Compare, _Alloc>::swap(std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]' at /opt/compiler-explorer/gcc-trunk-20230108/include/c++/13.0.0/bits/stl_map.h:1172:18, inlined from 'void f()' at <source>:8:14: /opt/compiler-explorer/gcc-trunk-20230108/include/c++/13.0.0/bits/stl_tree.h:2091:36: error: storing the address of local variable 'localMap' in '*MEM[(struct _Rb_tree_node_base * &)&localMap + 16].std::_Rb_tree_node_base::_M_parent' [-Werror=dangling-pointer=] 2091 | __t._M_root()->_M_parent = __t._M_end(); | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~ <source>: In function 'void f()': <source>:7:24: note: 'localMap' declared here 7 | std::map<int, int> localMap; | ^~~~~~~~ <source>:7:24: note: 'localMap.std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >::_M_t.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::_M_impl.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::_Rb_tree_impl<std::less<int>, true>::<unnamed>.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_M_parent' declared here cc1plus: all warnings being treated as errors Compiler returned: 1 Cheers, Romain