I am confused with regards how do compiler and linker deal with the fact that requirements on the caller of the function differ depending on if the function uses RVO or NRVO.
This could be my misunderstanding, but my assumption is that generally without RVO or NRVO
std::string s = get_string();
involves move construction of s from result of get_string if get_string does not do N?RVO but if get_string does N?RVO calling code does nothing and s
is constructed inplace by the function get_string.
EDIT: here is how I imagine get_string caller operating if there is no N?RVO:
- call get_string()
- get_string result is now on the stack, caller uses that to construct s
and now with RVO
- call get_string()
- when get_string is done there is no result on the stack, get_string constructed s, caller does not need to do anything to construct s.