Why are by-value parameters excluded from NRVO?

后端 未结 6 1695
孤独总比滥情好
孤独总比滥情好 2020-11-27 18:12

Imagine:

S f(S a) {
  return a;
}

Why is it not allowed to alias a and the return value slot?

S s = f(t);
S s          


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 19:11

    From t to a it is unreasonable to elide copy. The parameter is declared mutable, so copying is done because it is expected to be modified in function.

    From a to return value i can not see any reasons to copy. Perhaps it is some sort of oversight? The by-value parameters feel like locals inside function body ... i see no difference there.

提交回复
热议问题