<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,<br></div><div>-- <br><div class="gmail_signature"><div dir="ltr">Ehsan<br></div></div>
</div></div></div></div>