Re: C vs C++ style of interface for hardware abstraction lay
Posted: Fri Apr 19, 2013 6:03 pm
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 ):Falco Girgis wrote:Well goddamn. Thanks, Fillius and moreson. I was unaware of this.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.
Is this just new to C++11x, or did the old standards also work in such a manner?
Section 12.8, page 211: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.
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.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.