<div dir="ltr">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.</div><div class="gmail_extra"><br><div class="gmail_quote">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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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 class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>-- <br><div><div dir="ltr">Ehsan<br></div></div>
</div></font></span></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">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>