I had a hard time debugging a crash on production. Just wanted to confirm with folks here about the semantics. We have a class like ...
class Test { public: Test() { // members initialized ... m_str = m_str; } ~Test() {} private: // other members ... std::string m_str; }; Someone changed the initialization to use ctor initialization-lists which is reasonably correct within our code semantics. The order of initialization and their initial value is correct among other things. So the class looks like ...
class Test { public: Test() : /*other inits ,,, */ m_str(m_str) { } ~Test() {} private: // other members ... std::string m_str; }; But the code suddenly started crashing! I isolated the long list of inits to this piece of code m_str(m_str). I confirmed this via link text.
Does it have to crash? What does the standard say about this? (Is it undefined behavior?)
int i; i(i)in the initializer list: m_str(m_str) {}is bad code is pretty frightening.