I may be asking a stupid question, but I looked at the wikipedia page for RVO here and couldn't stop wondering if this behavior was wrong. I tried this on my machine and RVO kicked completely, despite the level of optimization. What if there was something BIG in the constructor? I know this should not, but what if? I canโt understand why RVO will happen anyway when side effects occur in the constructor.
EDIT: -fno-elide-constructors seems to stop RVO. But the question remains.
EDIT2: More importantly, how many people know about something like this? It may be in the standard, but it is still a very ugly function, as I see it. At the very least, compilers should disable it by default and provide a switch for people who know about it. :)
EDIT 3: I still insist that this is really bad. :). I donโt think I know of any other language restriction like this, directly against the syntax of the language. Does everything else throw compiler or linker errors?
c ++ return-value-optimization
nakiya
source share