<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 20, 2015 at 5:33 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra">I think this would be a great addition! In general, -Wshadow fires in a lot of situations, and I think having more granularity here is helpful for users.<br></div></blockquote><div><br></div><div>Note that -Wshadow doesn't diagnose this specific case, so my proposal isn't really a subset of -Wshadow.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Sat, Apr 18, 2015 at 11:05 AM, Ehsan Akhgari <span dir="ltr"><<a href="mailto:ehsan.akhgari@gmail.com" target="_blank">ehsan.akhgari@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div>Hi everyone,<br><br></div>I would like to propose adding a -Wshadow-field to clang. This flag would emit a warning if a derived class declares a member with the same name as one in one of the base classes, regardless of visibility.<br><br>Here is the rationale: In the Mozilla code base, there are fields that are often declared with the same name in thousands of classes, either by convention or through macros. One concrete example is mRefCnt, which is the variable holding the object's reference count. Every once in a while, we find bugs that are caused by the derived class inadvertently shadowing the base member, and therefore code in the derived class and its descendants in the hierarchy will access the wrong variable. In the case of mRefCnt, for example, these bugs are security sensitive since this typically causes the reference count of the object to get out of balance, causing use-after-free issues. One can conceive of other similar problems with other fields as well.<br><br></div>I was going to implement this warning in the clang plugin that we use for static analysis of our code base, but realized that this may probably be useful for other projects as well. Is there any interest in this feature? If yes, I would be happy to submit a patch.<br clear="all"><div><div><div><br></div><div>Cheers,<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div>-- <br><div><div dir="ltr">Ehsan<br></div></div>
</div></font></span></div></div></div>
<br></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr">Ehsan<br></div></div>
</div></div>