Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, just to clear up the paragraph that was previously here, using <code>b</code> in its own (dynamic) initialisation here is not UB. Before the expression is evaluated, <code>b</code> is not uninitialised but zero-initialised.</p> <hr> <p>The temporary <code>A</code> must live for precisely as long as the full expression:</p> <blockquote> <p>Temporary objects are destroyed as the last step in evaluating the full-expression (1.9) that (lexically) contains the point where they were created.</p> <p>[ISO/IEC 14882:2003(E) 12.2/3]</p> </blockquote> <p>The line <code>bool b = A(b).yield();</code> is a declaration, which is a statement, which is not an expression. The expression at hand is found only to the RHS of the <code>=</code>. [ISO/IEC 14882:2003(E) A.6]</p> <p>This would mean that the temporary should be destroyed <em>before</em> the dynamic initialisation takes place, no? Sure, the value <code>true</code> is held in the temporary that contains the result of the expression<sup>1</sup> until the initialisation completes, but the original <code>A</code> temporary should be destroyed before <code>b</code> is actually modified.</p> <p>Therefore I'd expect the output <code>false</code>, every time.</p> <hr> <p><sup>1</sup></p> <blockquote> <p>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"</p> <p>[ISO/IEC 14882:2003(E) 12.2/4]</p> </blockquote>
    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.
 

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