# V1050. Uninitialized class member is used when initializing the base class.

The analyzer has found that the base class constructor is called in the initializer list using uninitialized fields of a child class.

Consider the following example:

    struct C : public Base
    {
      C(int i) : m_i(i), Base(m_i) {};
      ....
      int m_i;
    };

The standard specifies that base classes are initialized first in the same order that they are declared. At the moment of calling the 'Base' constructor, the 'm_i' variable is not initialized yet. The code can be fixed as follows:

    struct C : public Base
    {
      C(int i) : m_i(i), Base(i) {};
      ....
      int m_i;
    };

The analyzer can also detect the use of uninitialized variables not only inside a class but also inside the base classes:

    struct Base1
    {
      Base1(int i) : m_base1(i) { };
      virtual ~Base1() = default;
      ....
      int m_base1;
    };

    struct Base2
    {
      Base2(int i) : m_base2(i) { };
      virtual ~Base2() = default;
      ....
      int m_base2;
    };
    struct C : public Base1, public Base2
    {
      C(int i) : m_i(i), Base1(m_base2), Base2(i) {};
      ....
      int m_i;
    };

If you need to initialize one base class with a field of another, make sure they are initialized in the right order:

    struct C : public Base2, public Base1
    {
      C(int i) : m_i(i), Base1(m_base2), Base2(i) {};
      ....
      int m_i;
    };

The V670 diagnostic is used to detect similar issues, but it focuses on bugs that have to do with the initialization order of fields of one class, when the variables are initialized in the same order that they are declared in the class.

This diagnostic is classified as:

CWE-457 CERT-EXP33-C CERT-EXP53-CPP

You can look at examples of errors detected by the V1050 diagnostic.