lundi 14 novembre 2022

[COVERITY][C++] Non-static class member "A._M_elems" is not initialized in this constructor nor in any functions that it calls

I am having an issue with a coverity warning that occurs in the constructor of my C++11 class.

In the class Model, I define the type Trajectory and declare it privately.

template<unsigned int T, unsigned int K>
class Model
{
public:
    typedef Eigen::Matrix<float, DEGREE, AXIS> State;
    typedef Eigen::Matrix<float, AXIS_COUNT, K> Sample;
    typedef std::array<std::array<Sample, T>, DEGREE> Trajectory;

private:
    Settings _settings;
    State _state;
    Trajectory _trajectory;

...

Later in the constructor section I define two constructors, the second one inherits from the first one. In the first one, I initialize the _trajectory variable in the double for loop.

...

public:
    Model(const Settings& settings, const State& initialState) :
     _settings(settings),
     _state(initialState)
    {
        for (unsigned int i = 0; i < DEGREE; i++)
            for (unsigned int j = 0; j < T; j++)
                _trajectory[i][j].setZero();
    };
    Model(const Settings& settings) :
     Model(settings, State::Zero()){};

    ~Model() = default;

...

This class is called by a handler which initializes Model with the second constructor. Everything works fine, however, once I run the coverity check, I receive the following error.


Non-static class member "_trajectory._M_elems" is not initialized in this constructor nor in any functions that it calls.

It is called at the line Model(settings, State::Zero()){};

I have tried many options but I cannot figure out how to initialize _trajectory properly without receiving this error.

I have tried this:

public:
    Model(const Settings& settings, const State& initialState) :
     _settings(settings),
     _state(initialState),
     _trajectory({})

this

public:
    Model(const Settings& settings, const State& initialState) :
     _settings(settings),
     _state(initialState),
     _trajectory()

this

public:
    Model(const Settings& settings, const State& initialState) :
     _settings(settings),
     _state(initialState),
     _trajectory(Trajectory)

and other combinations. None works.

Waiting for some legend to give me a hint.

Aucun commentaire:

Enregistrer un commentaire