On Tue, Jul 7, 2015 at 6:10 PM, Michael Layzell <mich...@thelayzells.com> wrote: > No, I never checked if it happens on an optimized build, but as C++ follows > an "as-if" principal, which means that code has to execute as if those > temporaries had been created. Unfortunately, AddRef and Release are virtual, > which, I'm pretty sure, means that the compiler can't optimize them out as > they may have arbitrary side effects :(. > > So the temporaries are probably eliminated, but the calls to AddRef and > Release are probably not. I could be wrong on this though.
This is true except in special cases where copy elision is allowed, in which case the temporary may be removed entirely, with its constructor and destructor. According to 12.8.32 of <http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>, one of those cases is "when a temporary class object that has not been bound to a reference (12.2) would be copied/moved to a class object with the same cv-unqualified type, the copy/move operation can be omitted by constructing the temporary object directly into the target of the omitted copy/move" I'm not an expert in C++-ese, but this looks like exactly that, so compilers should be allowed to remove the AddRef/Release. Whether they do or not is a separate question -- I'd hope so, in such a simple-looking case. _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform