by jcelerier · 4y ago · 0 comments
However, if you are compiling at -O0 without any optimizations this may not happen.
There are probably exceptions and loopholes just like with literally everything in C++, but there's this line:
> Return value optimization is mandatory and no longer considered as copy elision; see above.
Thanks for the clarification. Clang does do NRVO in that case but I guess it's obviously not guaranteed by the standard.
I guess it makes sense that an optimization that GCC is not able to do at all should not be part of the standard ; I'm pretty sure it should be possible to write cases that clang wouldn't be able to optimize either.