Ctor Initializer: self initialization causes crash?

后端 未结 5 1096
我寻月下人不归
我寻月下人不归 2021-01-22 10:18

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:
  Te         


        
5条回答
  •  逝去的感伤
    2021-01-22 11:00

    m_str is constructed in the initialization list. Therefore, at the time you are assigning it to itself, it is not fully constructed. Hence, undefined behavior.

    (What is that self-assignment supposed to do anyway?)

提交回复
热议问题