[PATCH] D18395: -Wshadow: don't warn on ctor parameters with the same name as a field name
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 23 09:30:15 PDT 2016
Reid sent out a different patch for this warning improvement. Have you
checked that one out? Is it abandoned?
I'm still a bit concerned about whitelisting all these cases & not catching
cases where the parameter is then used inside the function in some
problematic way (the classic being a unique_ptr parameter, moved into a
member, then the parameter (instead of the member) is referenced in the
body of the function).
On Wed, Mar 23, 2016 at 7:43 AM, Alexander Kornienko via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> alexfh created this revision.
> alexfh added reviewers: rsmith, rnk.
> alexfh added a subscriber: cfe-commits.
>
> -Wshadow: don't warn on ctor parameters with the same name as a field
> name. This fixes a broad class of false positives resulting from a widely
> used
> pattern:
>
> struct A {
> int q;
> A(int q) : q(q) {}
> };
>
> Fixes http://llvm.org/PR16088.
>
> http://reviews.llvm.org/D18395
>
> Files:
> lib/Sema/SemaDecl.cpp
> test/SemaCXX/warn-shadow.cpp
>
> Index: test/SemaCXX/warn-shadow.cpp
> ===================================================================
> --- test/SemaCXX/warn-shadow.cpp
> +++ test/SemaCXX/warn-shadow.cpp
> @@ -71,6 +71,14 @@
> };
> }
>
> +// http://llvm.org/PR16088
> +namespace PR16088 {
> +struct S {
> + int i;
> + S(int i) : i(i) {}
> +};
> +}
> +
> extern int bob; // expected-note {{previous declaration is here}}
>
> // rdar://8883302
> Index: lib/Sema/SemaDecl.cpp
> ===================================================================
> --- lib/Sema/SemaDecl.cpp
> +++ lib/Sema/SemaDecl.cpp
> @@ -6406,6 +6406,11 @@
> }
> }
>
> + // Don't warn on constructor parameters with the same name as a field
> name.
> + if (isa<FieldDecl>(ShadowedDecl) && isa<CXXConstructorDecl>(NewDC) &&
> + isa<ParmVarDecl>(D))
> + return;
> +
> DeclContext *OldDC = ShadowedDecl->getDeclContext();
>
> // Only warn about certain kinds of shadowing for class members.
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160323/37c0451a/attachment.html>
More information about the cfe-commits
mailing list