https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100699

            Bug ID: 100699
           Summary: g++ doesn't warn uninitialized field when the class is
                    derived from another class
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mytbk920423 at gmail dot com
  Target Milestone: ---

GCC doesn't warn on the following code when class B is a derived class.

----------------------- test.hh ---------------------------
#include <stdio.h>

class Base
{
        int v;
public:
        Base(int u): v(u) {}
        int get() { return v; }
};

class A
{
        int a;
public:
        A(int a_): a(a_) {}
        void print() { printf("%d\n", a); }
};

class B: public Base
{
        A a;
        int b;
public:
        B(int b_);
        void print() { a.print(); }
};
------------------ end of test.hh -----------------------

------------------------- test.cpp -------------------------
#include "test.hh"

B::B(int b_):
        Base(b_),
        a(b), b(100)
{}
------------------------ end of test.cpp -------------------

clang++ warns as follows:
$ clang++ -Og -g -Wall -Wextra -c test.cpp 
test.cpp:5:4: warning: field 'b' is uninitialized when used here
[-Wuninitialized]
        a(b), b(100)
          ^
1 warning generated.

Reply via email to