<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 25 September 2014 20:45, David Krauss <span dir="ltr">&lt;<a href="mailto:david_work@me.com" target="_blank">david_work@me.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><br><div><div>On 2014–09–25, at 4:52 AM, Richard Smith &lt;<a href="mailto:richardsmith@google.com" target="_blank">richardsmith@google.com</a>&gt; wrote:</div><br><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Then I&#39;m strongly opposed. It does not seem acceptable to silently change existing valid and well-defined code into having undefined behavior. I&#39;m sure I&#39;m not the only one who&#39;ll feel this way.</div></blockquote></div><br></span><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.</div></div></blockquote><div><br></div><div>Yes, that would nicely address one half of my concer. Essentially we&#39;d introduce a new class of program that is well-formed, but which an implementation is not required to translate (and can instead reject with a diagnostic).</div><div><br></div><div>The other half of my concern is portability: it is hugely painful to some audiences if a program is accepted by one compiler but rejected (or interpreted differently) by another, and indeed, the very purpose of having a standard is to minimize the occurrence of this problem. Making the diagnosis optional exacerbates this.</div><div><br></div><div>With the tweak discussed above, I don&#39;t see that we gain much over the status quo: either way, implementations can choose to detect this case, and either way, they can choose to diagnose or not. The *only* difference is that their &quot;conforming&quot; mode would be permitted to refuse to translate the program (which I claim is actually harmful for some audiences).</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>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 T&amp; or T&amp;&amp;, that is, “reference to type T” (8.3.2), shall be initialized by an object, or function, of type T or by an object that can be converted into a 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></blockquote><div><br></div><div>Perhaps; this is definitely imprecisely worded. Either there&#39;s a mixture of a compile-time and a runtime constraint here, or this really means &quot;lvalue of object or function type T&quot;. I suspect the latter.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><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"><span class="">extern int &amp; a;<br>int &amp; b = a;<br></span><span class="">int &amp; a = b;<br></span></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">    = [&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></blockquote><div><br></div><div>Yes, whatever we do specify, this example should not be made ill-formed.</div></div></div></div>