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.
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@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits