Spent most of the day trying to track a bug on my code that would only manifest in release mode with full optimizations. After going nuts with it, I finally came across an obscure and old copy constructor that wasn't being called by the new code due to a NVR optimization.
I know of RVO and NRVO for some time. But only today I came across its most obscure consequences. The question is what was the reasoning behind automatic NRV optimization when this clearly affects code flow? (RVO is not such an issue since under any case I can think of the elision of the copy constructor is obvious. But instead, NRVO is a tough nut to crack).
Seems to me rather odd that an optimization with such an impact in our code (it breaks the ANSI C 'As If' rule) be treated with such leniency(?). Visual Studio is particularly pernicious since apparently it doesn't allow me to control this particular optimization in separate. GCC does provide -fno-elide-constructors, but it's still too little.
I cannot even see if the optimization was applied at source level. I simply am not given any clue as to what is happening behind the stage. A language extension would be rather welcomed here. I don't mean syntactic sugar, but an implementation extension that allowed for a standardized way for compilers to show the optimization at source-level (or flag it at compile time). Why hasn't the Committee ever considered it?