Page MenuHomePhabricator

-Wshadow: don't warn on ctor parameters with the same name as a field name
AbandonedPublic

Authored by alexfh on Mar 23 2016, 7:43 AM.

Details

Reviewers
rnk
rsmith
Summary

-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.

As a data point: in a large code base this removes more than half of hits of -Wshadow, which all look useless (based on a manual inspection of a random sample of ~100 hits).

Diff Detail

Event Timeline

alexfh updated this revision to Diff 51416.Mar 23 2016, 7:43 AM
alexfh retitled this revision from to -Wshadow: don't warn on ctor parameters with the same name as a field name.
alexfh updated this object.
alexfh added reviewers: rsmith, rnk.
alexfh added a subscriber: cfe-commits.
alexfh updated this object.Mar 23 2016, 7:48 AM

Hm, didn't notice Reid's http://reviews.llvm.org/D18271, which seems to cover this in a better way.

alexfh abandoned this revision.Mar 23 2016, 7:56 AM

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).

Ah, now I see your follow-up email. Soryr I missed it...