Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it's allowed to print out true, or false, or for somewhat unrelated reasons, nothing at all.</p> <p>The true or false part is (as you've said), that the destruction of the temporary <code>A</code> object is not ordered with respect to the dynamic initialization of <code>b</code>.</p> <p>The nothing at all possibility is because the initialization of <code>b</code> is not ordered with respect to the creation/initialization of <code>std::cout</code>; when you try to destroy the temporary, <code>cout</code> may not have been created/initialized yet, so attempting to print something may not work at that point at all. [Edit: this is specific to C++98/03, and does not apply to C++11.]</p> <p>Edit: here is how I, at least, see the sequence:</p> <p><img src="https://i.stack.imgur.com/INTq5.png" alt="enter image description here"></p> <p>Edit2: After rereading §12.2/4 (yet again), I've changed the diagram again. §12.2/4 says:</p> <blockquote> <p>There are two contexts in which temporaries are destroyed at a different point than the end of the full expression. The first context is when an expression appears as an initializer for a declarator defining an object. In that context, the temporary that holds the result of the expression shall persist until the object’s initialization is complete. The object is initialized from a copy of the temporary; during this copying, an implementation can call the copy constructor many times; the temporary is destroyed after it has been copied, before or when the initialization completes.</p> </blockquote> <p>I believe this expression is an initializer for a declarator defining an object, so it's required to initialize the object from a copy of the value of the expression (<code>true</code>, in this case), not directly from the return value. In the case of <code>true</code>, this is probably a distinction without a difference, but I think the diagram is technically more accurate as it stands right now.</p> <p>This also makes fairly clear (I think) that the temporary holding <code>true</code> does <em>not</em> have to be destroyed at the end of the full expression, so I've re-drawn the diagram to reflect that as well.</p> <p>This section is gone in C++0x/C++11, so I've re-drawn the diagram (yet again) to show the difference between the two (and how much simpler this piece has gotten in C++11).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload