Fillius wrote:there is a problem with the example provided. You effectively prevent the compiler from optimizing away all temporaries by making your constructors non-trival(because of the debug output).
The last published draft of the current C++ Standard dictates that a non-trivial constructor of temporaries must be called:
In Section 12.2, Page 259:
When an implementation introduces a temporary object of a class that has a non-trivial constructor (12.1,
12.8), it shall ensure that a constructor is called for the temporary object.
Well goddamn. Thanks, Fillius and moreson. I was unaware of this.
Is this just new to C++11x, or did the old standards also work in such a manner?
I thought so, the example I compiled in that last post to prove my statement was compiled without the -std=c++11 or std=c++0x flags after all, but just to be entirely certain I dug out a copy of the c++03 standard and found the same paragraph in section 12.2, this time one page 191(68 Pages difference, the standard sure has grown ):
When an implementation introduces a temporary object of a class that has a non-trivial constructor (12.1), it
shall ensure that a constructor is called for the temporary object. Similarly, the destructor shall be called for
a temporary with a non-trivial destructor (12.4). Temporary objects are destroyed as the last step in evalu-
ating the full-expression (1.9) that (lexically) contains the point where they were created. This is true even
if that evaluation ends in throwing an exception.
Section 12.8, page 211:
When certain criteria are met, an implementation is allowed to omit the copy construction of a class object,
even if the copy constructor and/or destructor for the object have side effects.
I dont have a copy of the c++98 standard, so I cant say for sure if it has always been that way, sorry about that.
Last edited by Fillius on Fri Apr 19, 2013 6:22 pm, edited 1 time in total.
Falco Girgis wrote:Fillius, you are Philipp of 2D Retrospectives, right? I tracked you down from your email address!
2D house of terror looks fantastic! We have a few very seasoned DC developers here. We should talk about some Dreamcast code sometime!
You are right, I am. Thank you very much for the compliment, its not all too great of a game so, just a very small Mario Party like game in 2D, not even close to half as impressive as what has been shown of Elysian Shadows.
I would love to talk about code, anytime, I wrote you a message on facebook