Spurious -Wmaybe-uninitialized warnings #46

Closed
opened 2024-03-15 20:46:23 +00:00 by jade · 1 comment
Owner

This is a gcc bug which we will file at some point. Fixed by switching to -O2 though:

lix/lix2 » cat meow2.sh
g++ -std=c++2a -O3 -c -Wall meow.cc
lix/lix2 » cat meow.cc
#include <map>
#include <string>
struct Base { bool b; std::map<int, int> m; };
struct Derived : Base { std::string s; };
void foo(const std::string & s) { Derived d{{}, s}; }
lix/lix2 » sh meow2.sh
In file included from /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/map:60,
                 from meow.cc:1:
In member function ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_mbegin() const [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 ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_begin() [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> >]’ at /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_tree.h:741:25,
    inlined from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::~_Rb_tree() [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> >]’ at /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_tree.h:986:17,
    inlined from ‘std::map<_Key, _Tp, _Compare, _Alloc>::~map() [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]’ at /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_map.h:312:7,
    inlined from ‘void foo(const std::string&)’ at meow.cc:5:50:
/nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_tree.h:737:73: warning: ‘d.Derived::<unnamed>.Base::m.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>::<anonymous>.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_M_parent’ may be used uninitialized [-Wmaybe-uninitialized]
  737 |       { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
      |                                                                         ^
meow.cc: In function ‘void foo(const std::string&)’:
meow.cc:5:43: note: ‘d’ declared here
    5 | void foo(const std::string & s) { Derived d{{}, s}; }
      |                                           ^
This is a gcc bug which we will file at some point. Fixed by switching to -O2 though: ``` lix/lix2 » cat meow2.sh g++ -std=c++2a -O3 -c -Wall meow.cc lix/lix2 » cat meow.cc #include <map> #include <string> struct Base { bool b; std::map<int, int> m; }; struct Derived : Base { std::string s; }; void foo(const std::string & s) { Derived d{{}, s}; } lix/lix2 » sh meow2.sh In file included from /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/map:60, from meow.cc:1: In member function ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_mbegin() const [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 ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_begin() [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> >]’ at /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_tree.h:741:25, inlined from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::~_Rb_tree() [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> >]’ at /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_tree.h:986:17, inlined from ‘std::map<_Key, _Tp, _Compare, _Alloc>::~map() [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]’ at /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_map.h:312:7, inlined from ‘void foo(const std::string&)’ at meow.cc:5:50: /nix/store/fdiknsmnnczx6brsbppyljcs9hqckawk-gcc-12.3.0/include/c++/12.3.0/bits/stl_tree.h:737:73: warning: ‘d.Derived::<unnamed>.Base::m.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>::<anonymous>.std::_Rb_tree_header::_M_header.std::_Rb_tree_node_base::_M_parent’ may be used uninitialized [-Wmaybe-uninitialized] 737 | { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); } | ^ meow.cc: In function ‘void foo(const std::string&)’: meow.cc:5:43: note: ‘d’ declared here 5 | void foo(const std::string & s) { Derived d{{}, s}; } | ^ ```
Author
Owner
GCC bug filed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114360
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#46
No description provided.