std::vector not initialized by default ctor

122 Views Asked by At

I encountered some strange behaviour with GCC-4.8 while initializing std::vector within default ctor of class. My code is the following:

class TestLogger final: public Logger
{
public:   
  void LogWarning(const std::string& msg,) const override{
    this->mWarningMessages.emplace_back(msg);
  }

  bool ContainsWarnings() const{
    return !this->mWarningMessages.empty();
  }

private:
  mutable std::vector<std::string> mWarningMessages;  // needs to be mutable because it's changed by const method
};

What happens if I use some object of my class TestLogger? That member mWarningMessages seems to not be initialized.

See following code:

int main(int argc, char *arcv[])
{
  TestLogger logger;
  bool shouldBeFalse = logger.ContainsWarnings() // --> false expected, but returns true;
}

If I implement the default constructor of class TestLogger by myself with mWarningMessages in initializer list, everything works perfect.

Does anybody have a clue why my code without default ctor is not working? I would've expected mWarningMessage to be initialized properly by auto-generated default ctor of my class TestLogger. Might this be a bug in GCC-4.8?

Thanks for your help

0

There are 0 best solutions below