What comes first - stack unwinding or copying of return values

前端 未结 4 2192
清歌不尽
清歌不尽 2020-12-10 12:15

Is the mutex used in method GetValues() released before or after copy constructing the dummy instance?

         


        
4条回答
  •  隐瞒了意图╮
    2020-12-10 12:39

    Yes:-). Formally, there are two “copies” when returning a value: one to some special place used to actually return the value, and the second after the return, to wherever the value must be finally placed. Either or both can be optimized out, however. The destruction of local variables occurs after the first, but before the second. (NRVO and RVO may lead to the first being optimized out, but they don't affect your code, since you're not returning a local variable.)

提交回复
热议问题