Does returning by const value affect return value optimization? [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 08:46:09

问题


Consider the function

const std::string f()
{
    return "hello";
}

And the call

std::string x = f();

Regardless of whether value return types should be const or not, does the fact the return value is const, prevent a compiler from performing return value optimization?

My understanding of RVO is that the returned object is constructed directly into the variable outside the function. However, if the return type is const T, this isn't the same as a T, so will RVO be prevented?

来源:https://stackoverflow.com/questions/25360617/does-returning-by-const-value-affect-return-value-optimization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!