https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127477
Bug ID: 127477
Summary: Bogus uninitialized warning when accessing base class
member through a derived class from another base class
during construction
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: joaquin.lopezmunoz at gmail dot com
Target Milestone: ---
The following:
struct Node { Node* a; Node* b; };
struct Final;
struct Holder { Node* member; Holder(); };
struct Base { long pad; Base(); Node* header() const; };
struct Pad { long x; Pad(); };
struct Final : Pad, Holder, Base {
Final() : Pad(), Holder(), Base() {}
Node* final_header() const { return Holder::member; }
};
inline Node* Base::header() const
{ return static_cast<const Final*>(this)->final_header(); }
Node* make() { return new Node; }
Holder::Holder() : member(make()) {}
Pad::Pad() : x(0) {}
Base::Base() : pad(0) { header()->a = header()->b = header(); }
int main() { Final f; }
issues a incorrect uninitialized warning when compiled with -Wall - Wextra
-Werror -Wuninitialized -O1. GCC 15 compiles without warning for the same
commandline options.
In member function 'Node* Final::final_header() const',
inlined from 'Node* Base::header() const' at <source>:13:55,
inlined from 'Base::Base()' at <source>:18:59:
<source>:9:47: error: '((const
Final*)this)[768614336404564650].Final::Holder.Holder::member' is used
uninitialized [-Werror=uninitialized]
9 | Node* final_header() const { return Holder::member; }
| ^~~~~~
cc1plus: all warnings being treated as errors
Live example at Compiler Explorer:
https://godbolt.org/z/Mxsv3r4ez
Example code reduced from real-life report from a user of Boost.MultiIndex.
Unfortunately, I can't provide the preprocessed file as per bug reporting
instructions (testing with Compiler Explorer).