<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014–09–25, at 4:52 AM, Richard Smith &lt;<a href="mailto:richardsmith@google.com">richardsmith@google.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Then I'm strongly opposed. It does not seem acceptable to silently change existing valid and well-defined code into having undefined behavior. I'm sure I'm not the only one who'll feel this way.</div></blockquote></div><br><div>True, nobody gains anything from the possibility of non-diagnosis and a crash-on-run executable. But that’s not in practice going to happen except as a result, as you put it, of the compiler doing nothing special in particular. If the implementation notices the out-of-thin-air result at all, that suggests the existence of some exception handling which provides an opportunity for diagnosis.</div><div><br></div><div>Perhaps there should be some specification like static UB diagnosis, where a particular expression is ill-formed/NDR but behavior is well-defined if it is neither diagnosed nor evaluated. The current wording of [dcl.init.ref] 8.5.3/1 actually comes pretty close:</div><div><br></div><div><blockquote type="cite">A variable declared to be a&nbsp;T&amp;&nbsp;or&nbsp;T&amp;&amp;, that is, “reference to type&nbsp;T” (8.3.2), shall be initialized by an object,&nbsp;or function, of type&nbsp;T&nbsp;or&nbsp;by an object that can be converted into a&nbsp;T.</blockquote></div><div><br></div><div>This is a “shall be” requirement applied to a runtime occurrence. Although, it perhaps intends only to constrain the type of an initializer expression.</div><div><br></div><div>Does portability suffer from NDR? Sure. But the main suggestion here is to weed out nonsense with a new diagnosis. If some customer can’t live with a hard error, issuing a warning and producing an executable also satisfies NDR.</div><div><br></div><div>Non-diagnosis and UB right at static initialization is the status quo for Clang and GCC, given this declaration sequence which portably specifies a defective product:</div><div><br></div><div><font face="Courier">extern int &amp; a;<br>int &amp; b = a;<br>int &amp; a = b;<br></font><br></div><div>The only other way I know to get circular reference initialization is in a constructor, between two member references, which Clang does diagnose by default as use of an uninitialized variable. GCC’s -Wuninitialized is also an area of active development.</div><div><br></div><div>On the other hand, there are ways to use a reference in its own initializer which are not unreasonable:</div><div><br></div><div><font face="Courier">std::function&lt; void( int ) &gt; &amp;&amp; f</font></div><div><font face="Courier">&nbsp; &nbsp; = [&amp;] ( int cnt ) { if ( cnt ) f( -- cnt ); };</font></div><div><br></div><div>Stronger analysis might be better when it comes to checking initialization.</div><div><br></div></body></html>