Reading clause 1.9/14 of the C++0x draft. There I find:
Every value computation and side effect associated with a full-expression is sequenced before every value computation and side effect associated with the next full-expression to be evaluated.8)
And the footnote 8 says
8) As specified in 12.2, after a full-expression is evaluated, a sequence of zero or more invocations of destructor functions for temporary objects takes place, usually in reverse order of the construction of each temporary object.
What does it mean by "usually"? I thought the reverse order of destruction was the rule.
I assume they're referring to any temporaries bound to references. The lifetime of the temporary is extended to the lifetime of the reference, while other temporaries may still be destroyed.
Along with Mark B's answer (which is quite good) there's one other situation: if you create a temporary object of a type that's accessed via a forward iterator, the objects (obviously enough) created in the order supported by the iterator and also destroyed in the same order (not the reverse -- because the iterator doesn't support that). I don't remember for sure, but I seem to recall the same happening (or at least being allowed) even if the container in question would support reverse iteration (so the code in question can ignore the container/iterator type, presumably).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With