Forgot to CC the list..<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Daniel Jasper</b> <span dir="ltr"><<a href="mailto:djasper@google.com">djasper@google.com</a>></span><br>
Date: Thu, Jan 12, 2012 at 7:26 PM<br>Subject: Re: [cfe-commits] Clang change to detect and warn about unused private members<br>To: Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>><br><br><br>
Hi Nico,<div><br></div><div>comments inline.<br><br><div class="gmail_quote"><div class="im">On Wed, Jan 11, 2012 at 10:49 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Daniel,<br>
<div><br>
On Wed, Jan 11, 2012 at 1:11 AM, Daniel Jasper <<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>> wrote:<br>
> Hi,<br>
><br>
> the attached change is designed to detect and warn about private unused<br>
> members of C++ classes. It checks whether a class is fully defined in the<br>
> current translation unit, i.e. all methods are either defined or pure<br>
> virtual and all friends are defined. Otherwise, the private member could be<br>
> used by a function defined in another translation unit.<br>
<br>
</div>that's a cool warning! Here are a few cases where it flags false<br>
positives (it finds tons of true positives too, but those are boring<br>
:-) ).<br>
<br>
It flags |stackArray| in ICU's cmemory.h. This is declared for storage<br>
and accessed through pointer aliasing, probably not much that can be<br>
done about this:<br>
<a href="http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/third_party/icu/source/common/cmemory.h&exact_package=chromium&q=file:cmemory.h&l=285" target="_blank">http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/third_party/icu/source/common/cmemory.h&exact_package=chromium&q=file:cmemory.h&l=285</a></blockquote>

<div><br></div></div><div>As you said in the other email, it is the wrong code line and I think, it is correct to warn about the other |stackArray|.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
In flags StaticResource::instance_ in v8's utils.h:<br>
<a href="http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/v8/src/utils.h&exact_package=chromium&q=file:v8/src/utils.h&l=300" target="_blank">http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/v8/src/utils.h&exact_package=chromium&q=file:v8/src/utils.h&l=300</a><br>


This is supposed to be accessed through the class below, Access, which<br>
is a friend of utils.h. Do you check if any friends use private<br>
variables?<br></blockquote><div><br></div></div><div>Yes, I check friends. This is a bug, I know why it happens (it is because of the dependent templates) and I will fix it.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


In chromium itself, it flags ShadowingAtExitManager member variables.<br>
This is basically a RAII class which only exists to call a protected<br>
superclass constructor, and which only exists if UNIT_TESTS is<br>
defined: <a href="http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/base/at_exit.h&l=71" target="_blank">http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/base/at_exit.h&l=71</a><br>
So maybe the "constructor without arguments" heuristic could be<br>
tweaked to exclude constructors that call superclass constructors with<br>
arguments?<br>
(Here's another RAII class whose constructor takes 0 arguments:<br>
<a href="http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/base/logging_unittest.cc&exact_package=chromium&q=logstatesaver&l=26" target="_blank">http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/base/logging_unittest.cc&exact_package=chromium&q=logstatesaver&l=26</a><br>


)<br></blockquote><div><br></div></div><div>I have changed it to be more conservative (I will send a new patch once I have fixed the bug mentioned above). It now only accepts members without initializer or with an argument-less initializer, if the field's type has a trivial default constructor and a trivial destructor. Unfortunately, we now also miss a lot of true positives, but I guess the false positives are worse, especially because there is no easy way to explicitly suppress the warning for these cases within the standard syntax.</div>

<div><br></div><div>Cheers,<br>Daniel</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
(This is not an exhaustive list, just the things I found after a quick look.)<br>
<span><font color="#888888"><br>
Nico<br>
</font></span></blockquote></div></div><br></div>
</div><br>