<div dir="ltr">Seems reasonable to me.</div><div class="gmail_extra"><br><div class="gmail_quote">On 10 August 2017 at 14:28, Hans Wennborg via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Should we merge this to 5.0?<br>
<div class="HOEnZb"><div class="h5"><br>
On Mon, Jul 31, 2017 at 8:21 AM, Alexander Kornienko via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: alexfh<br>
> Date: Mon Jul 31 08:21:26 2017<br>
> New Revision: 309569<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=309569&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=309569&view=rev</a><br>
> Log:<br>
> Fix -Wshadow false positives with function-local classes.<br>
><br>
> Summary:<br>
> Fixes <a href="http://llvm.org/PR33947" rel="noreferrer" target="_blank">http://llvm.org/PR33947</a>.<br>
><br>
> <a href="https://godbolt.org/g/54XRMT" rel="noreferrer" target="_blank">https://godbolt.org/g/54XRMT</a><br>
><br>
> void f(int a) {<br>
> struct A {<br>
> void g(int a) {}<br>
> A() { int a; }<br>
> };<br>
> }<br>
><br>
> 3 : <source>:3:16: warning: declaration shadows a local variable [-Wshadow]<br>
> void g(int a) {}<br>
> ^<br>
> 1 : <source>:1:12: note: previous declaration is here<br>
> void f(int a) {<br>
> ^<br>
> 4 : <source>:4:15: warning: declaration shadows a local variable [-Wshadow]<br>
> A() { int a; }<br>
> ^<br>
> 1 : <source>:1:12: note: previous declaration is here<br>
> void f(int a) {<br>
> ^<br>
> 2 warnings generated.<br>
><br>
> The local variable `a` of the function `f` can't be accessed from a method of<br>
> the function-local class A, thus no shadowing occurs and no diagnostic is<br>
> needed.<br>
><br>
> Reviewers: rnk, rsmith, arphaman, Quuxplusone<br>
><br>
> Reviewed By: rnk, Quuxplusone<br>
><br>
> Subscribers: Quuxplusone, cfe-commits<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D35941" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D35941</a><br>
><br>
> Modified:<br>
> cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
> cfe/trunk/test/SemaCXX/warn-<wbr>shadow.cpp<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=309569&r1=309568&r2=309569&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDecl.cpp?rev=309569&r1=<wbr>309568&r2=309569&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp Mon Jul 31 08:21:26 2017<br>
> @@ -6999,6 +6999,21 @@ void Sema::CheckShadow(NamedDecl *D, Nam<br>
> return;<br>
> }<br>
> }<br>
> +<br>
> + if (cast<VarDecl>(ShadowedDecl)-><wbr>hasLocalStorage()) {<br>
> + // A variable can't shadow a local variable in an enclosing scope, if<br>
> + // they are separated by a non-capturing declaration context.<br>
> + for (DeclContext *ParentDC = NewDC;<br>
> + ParentDC && !ParentDC->Equals(OldDC);<br>
> + ParentDC = getLambdaAwareParentOfDeclCont<wbr>ext(ParentDC)) {<br>
> + // Only block literals, captured statements, and lambda expressions<br>
> + // can capture; other scopes don't.<br>
> + if (!isa<BlockDecl>(ParentDC) && !isa<CapturedDecl>(ParentDC) &&<br>
> + !isLambdaCallOperator(<wbr>ParentDC)) {<br>
> + return;<br>
> + }<br>
> + }<br>
> + }<br>
> }<br>
> }<br>
><br>
><br>
> Modified: cfe/trunk/test/SemaCXX/warn-<wbr>shadow.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-shadow.cpp?rev=309569&r1=309568&r2=309569&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/warn-shadow.cpp?rev=<wbr>309569&r1=309568&r2=309569&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/SemaCXX/warn-<wbr>shadow.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/warn-<wbr>shadow.cpp Mon Jul 31 08:21:26 2017<br>
> @@ -213,3 +213,12 @@ typedef int externC; // expected-note {{<br>
> void handleLinkageSpec() {<br>
> typedef void externC; // expected-warning {{declaration shadows a typedef in the global namespace}}<br>
> }<br>
> +<br>
> +namespace PR33947 {<br>
> +void f(int a) {<br>
> + struct A {<br>
> + void g(int a) {}<br>
> + A() { int a; }<br>
> + };<br>
> +}<br>
> +}<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>