<div dir="ltr"><div>Thanks, James! I think I have only one more substantive comment:</div><div><br></div><div>+ (Field->getAccess() == AS_public || Field->getAccess() == AS_protected)) {<br></div><div><br></div><div>Have you considered also taking into account the access of the inheritance path? Eg, a public member of a private base class of a public base class is typically inaccessible, even though it was declared public:</div><div><br></div><div> struct A { int n; };</div><div> struct B : private A {};</div><div> struct C : B { int n; }; // A::n is not accessible here, should we suppress the warning?</div><div><br></div><div>You can use CXXRecordDecl::MergeAccess to combine the access of the path with the access of the field and compute the effective access of the field in the derived class (and you should test to see if the resulting access is AS_None to tell if the field is inaccessible; fields with effective access of AS_Private -- such as public members of a private direct base class -- are accessible from the derived class). You'll need to set RecordPaths to true in the CXXBasePaths object in order for lookupInBases to compute the path access.</div><div><br></div><div>Oh, and you may as well use a range-based for loop here:</div><div><br></div><div><div>+ auto Result = Base->lookup(FieldName);</div><div>+ for (auto I = Result.begin(); I != Result.end(); ++I) {</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 February 2017 at 00:19, James Sun <span dir="ltr"><<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="m_-8845092313379657209WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Hi Richard<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks for the feedback! Hopefully addressed!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">James<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri;color:black">From: </span>
</b><span style="font-family:Calibri;color:black"><<a href="mailto:metafoo@gmail.com" target="_blank">metafoo@gmail.com</a>> on behalf of Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>><br>
<b>Date: </b>Wednesday, February 1, 2017 at 3:50 PM<br>
<b>To: </b>James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>></span></p><div><div class="h5"><br>
<b>Cc: </b>Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>>, "<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>, Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>><br>
<b>Subject: </b>Re: Add warning for c++ member variable shadowing<u></u><u></u></div></div><p></p>
</div><div><div class="h5">
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">+ std::set<StringRef> bases; <u></u><u></u></p>
<div>
<p class="MsoNormal">+ const auto baseName = Specifier->getType()-><wbr>getAsCXXRecordDecl()->getName(<wbr>);<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Please capitalize local variable names. Also, please don't use the record name as a key in your set; that's not guaranteed to be unique. Instead, you could either use a set of canonical types or of canonical CXXRecordDecl*s.<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">+ for (const auto *Field : Specifier->getType()-><wbr>getAsCXXRecordDecl()->fields()<wbr>) {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ if ((Field->getAccess() == AS_public || Field->getAccess() == AS_protected) &&<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ Field->getName() == FieldName) {<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Use Specifier->getType()-><wbr>getAsCXXRecordDecl()->lookup(<wbr>Field->getName()) here to look up the field by name, rather than walking all the fields of all base classes and checking if each of them has the right name. You should also check for
IndirectFieldDecls, for this case:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"> struct A {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> union { int x; float f; };<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> };<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> struct B : A {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> int x;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> };<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">+ bases.emplace(baseName);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">It's more efficient to use insert rather than emplace when inserting an element into a set.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">+ Diag(Loc, diag::warn_shadow_field)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ << FieldName << RD->getName() << baseName;<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">It'd be nice to add a note here pointing at the base class member that was shadowed.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On 31 January 2017 at 19:20, James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Fixed!</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri;color:black">From:
</span></b><span style="font-family:Calibri;color:black">Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>><br>
<b>Date: </b>Tuesday, January 31, 2017 at 6:53 PM</span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<b>To: </b>James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>><br>
<b>Cc: </b>Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>>, "<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>,
Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>><br>
<b>Subject: </b>Re: Add warning for c++ member variable shadowing<u></u><u></u></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Hmm, the braces in the if (bases.find(...)...) are not needed.
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Could you also add a test case for virtual inheritance?<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Mon, Jan 30, 2017 at 8:34 PM, James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Hi Saleem</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks for the quick response. A test case is added. It covers some ordinary cases as well as corner cases like multiple paths
to the same base.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">James</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri;color:black">From:
</span></b><span style="font-family:Calibri;color:black">Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>><br>
<b>Date: </b>Monday, January 30, 2017 at 6:50 PM<br>
<b>To: </b>James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>><br>
<b>Cc: </b>Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>>, "<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>,
Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<b>Subject: </b>Re: Add warning for c++ member variable shadowing<u></u><u></u></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I think that the patch is starting to look pretty good!
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Can you add some test cases for the particular cases to diagnose in a separate test set to ensure that we have proper coverage of the various cases rather than relying on the existing
test cases? Something to make sure that we get the simple case right as well as the complex cases (e.g. we don't print duplicate warnings for multiple paths).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Mon, Jan 30, 2017 at 5:50 PM, James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Hi Richard</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Sorry for the late reply. Thank you for giving the feedback! The updated version is attached. Please let me know if there is anything
improper.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">James</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri;color:black">From:
</span></b><span style="font-family:Calibri;color:black"><<a href="mailto:metafoo@gmail.com" target="_blank">metafoo@gmail.com</a>> on behalf of Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>><br>
<b>Date: </b>Friday, January 27, 2017 at 3:03 PM<br>
<b>To: </b>James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>><br>
<b>Cc: </b>Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>>, "<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>,
Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<b>Subject: </b>Re: Add warning for c++ member variable shadowing<u></u><u></u></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">+def warn_shadow_member_variable : Warning<<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ "shadowed variable '%0' in type '%1' inheriting from type '%2'">,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">The phrasing of this is incorrect: the things you're warning about are not variables, they're non-static data members. Perhaps something like:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> "non-static data member '%0' of '%1' shadows member inherited from type '%2'"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ InGroup<Shadow>;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Would it make sense to put this in a subgroup of -Wshadow so that it can be controlled separately?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">+ /// Check if there is a member variable shadowing<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Please end comments in a period.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ void CheckShadowInheritedVariables(<wbr>const SourceLocation &Loc,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Likewise, 'Variables' is wrong. We would typically use the C term 'Fields' for these cases within Clang sources.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">+ for (const auto &Base : DC->bases()) {<u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">+ if (const auto *TSI = Base.getTypeSourceInfo())<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ if (const auto *BaseClass = TSI->getType()-><wbr>getAsCXXRecordDecl()) {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ for (const auto *Field : BaseClass->fields())<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ if (Field->getName() == FieldName)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ Diag(Loc, diag::warn_shadow_member_<wbr>variable)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ << FieldName << RD->getName() << BaseClass->getName();<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ // Search parent's parents<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ <wbr>CheckShadowInheritedVariables(<wbr>Loc, FieldName, RD, BaseClass);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">+ }<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Maybe we should avoid diagnosing shadowing of members that are inaccessible from the derived class? What about if the field name is ambiguous? Also, we shouldn't recurse if lookup
finds something with the given name in this class, and ideally we would only visit each class once, even if it appears multiple times in a multiple-inheritance scenario. CXXRecordDecl::lookupInBases can handle most of these cases for you automatically, and
will also let you build a set of paths to problematic base classes in case you want to report those.<u></u><u></u></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">On 24 January 2017 at 20:52, James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks for the comments. The new version is attached.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Wrt two of your questions:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">(1) “The description that you have on <wbr>CheckShadowInheritedVariables isn't really the type of comments that we have in doxygen
form. Im not sure if its in line with the rest of the code.”</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">I’ve read through the doxygen wiki; hopefully it’s fixed; let me know if it’s still wrong</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">(2) “Why are you checking that the DeclContext has a definition rather than the record itself?”</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">There are cases like “struct A; struct B : A {};”, where A does not have a definition. The compiler will hit an assertion failure
if we call A.bases() directly.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Thanks</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">James</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"> </span><u></u><u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-family:Calibri;color:black">From:
</span></b><span style="font-family:Calibri;color:black">Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>><br>
<b>Date: </b>Tuesday, January 24, 2017 at 7:10 PM<br>
<b>To: </b>James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>><br>
<b>Cc: </b>"<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>, Aaron Ballman <<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>>,
Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>><br>
<b>Subject: </b>Re: Add warning for c++ member variable shadowing</span><u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Some more stylistic comments:
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">The description that you have on <wbr>CheckShadowInheritedVariables isn't really the type of comments that we have in doxygen form. Im not sure if its in line with the rest of the code.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">The ignore warning comments are restating what is in the code, please remove them.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Could you make the header and the source file match the name?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Why are you checking that the DeclContext has a definition rather than the record itself?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Space after the <<.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Don't use the cast for the check, use isa. Although, since you use the value later, it is probably better to write this as:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> if (const auto *RD = cast<CXXRecordDecl>(<wbr>CurContext))<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> CheckShadowInheritedVariabless<wbr>(Loc, Name.getAsString(), RD, RD);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Tue, Jan 24, 2017 at 4:06 PM, James Sun via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Coding style change</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:black">From:
</span></b><span style="color:black">James Sun <<a href="mailto:jamessun@fb.com" target="_blank">jamessun@fb.com</a>><br>
<b>Date: </b>Tuesday, January 24, 2017 at 2:36 PM<br>
<b>To: </b>"<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject: </b>Add warning for c++ member variable shadowing</span><u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt">Dear members</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Here is a patch (attached) to create warnings where a member variable shadows the one in one of its inheriting classes. For cases where we really
don't want to shadow member variables, e.g. </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">class a {</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> int foo;
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">}</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">class b : a {
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> int foo; // Generate a warning</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">}</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">This patch
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">(1) adds a member variable shadowing checking, and
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">(2) incorporates it to the unit tests.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Comments are welcome.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt">James</span><u></u><u></u></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=ikRH8URaurZA7JMys57d3w&m=lheFEjRie_ahss0mWHaJIa1eNMlFv2DMH5ZWHGQvo8U&s=750RLygVMQIDJB7IKBhOef4zIDHerGwb7aJZAY2aP9U&e=" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<p class="MsoNormal">Saleem Abdulrasool<br>
compnerd (at) compnerd (dot) org<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<p class="MsoNormal">Saleem Abdulrasool<br>
compnerd (at) compnerd (dot) org<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<p class="MsoNormal">Saleem Abdulrasool<br>
compnerd (at) compnerd (dot) org<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>
</blockquote></div><br></div>