<div dir="ltr">Quentin,<div><br></div><div>Clang does not have a warning for uninitialized fields in class methods. I've looked before to add a warning to flag any unused fields at the end of the a constructor. However, there were good reasons to have uninitialized fields, such as having an Init() method later that initializes the fields, or a guard variable to protect against uninitialized use. Also, -Wuninitialized typically warns on the use of an uninitialized variable, not the mere presence of one.</div>
<div><br></div><div>The other idea is to do cross method analysis, either using the control flow of a program to determine which methods are used in which order, or testing methods against constructors. Such an analysis would likely be too expensive, and would be more suited for static analysis.</div>
<div><br></div><div>So there's no warning for this yet, and probably won't be unless we find a better way to detect it.</div><div><br></div><div>Richard<br></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 14, 2014 at 5:15 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Adding Richard explicitly here. :)</p>
<div class="gmail_quote">On Mar 14, 2014 4:32 PM, "Quentin Colombet" <<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hi,<div><br></div><div>I recently found a non-deterministic behavior in my application that was due to a missing field initialization.</div><div>Here is a snippet of the actual problem:</div>
<div><div><br></div><div>struct foo {</div><div> foo() {}; // <— bar is not initialized here.</div><div> int getBar() const {</div><div> return bar; // <— this returns an uninitialized value.</div><div> }</div>
<div>private:</div><div> int bar;</div><div>};</div></div><div><br></div><div>I’ve compiled the attached cpp file that contains this snippet with <span style="font-family:Menlo;font-size:11px">-Wall -Wextra -Wuninitialized</span>, but no warning is issued (trunk <span style="font-family:Menlo;font-size:11px">203678</span>).</div>
<div>Is there an option to make clang warn about that?</div><div><br></div><div>If not, should I file a PR?</div><div><br></div><div>Thanks,<br><div>
<div style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;text-transform:none;white-space:normal;font-family:Helvetica;word-wrap:break-word;word-spacing:0px">
-Quentin</div>
</div>
</div></div><br><div style="word-wrap:break-word"><div></div></div>
<br>_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@cs.uiuc.edu" target="_blank">cfe-users@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users</a><br>
<br></blockquote></div>
</blockquote></div><br></div>