Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -12141,6 +12141,18 @@ if (!Param->getType().isConstQualified()) Diag(Param->getLocation(), diag::err_attribute_pointers_only) << Attr->getSpelling() << 1; + + // Check for parameter names shadowing fields from the class. + if (LangOpts.CPlusPlus && !Param->isInvalidDecl()) { + // The owning context for the parameter should be the function, but we + // want to see if this function's declaration context is a record. + DeclContext *DC = Param->getDeclContext(); + if (DC && DC->isFunctionOrMethod()) { + if (auto *RD = dyn_cast(DC->getParent())) + CheckShadowInheritedFields(Param->getLocation(), Param->getDeclName(), + RD, /*DeclIsField*/ false); + } + } } return HasInvalidParm; Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -12427,13 +12427,6 @@ D.setInvalidType(true); } } - - if (LangOpts.CPlusPlus) { - DeclarationNameInfo DNI = GetNameForDeclarator(D); - if (auto *RD = dyn_cast(CurContext)) - CheckShadowInheritedFields(DNI.getLoc(), DNI.getName(), RD, - /*DeclIsField*/ false); - } } // Temporarily put parameter variables in the translation unit, not Index: test/SemaCXX/warn-shadow.cpp =================================================================== --- test/SemaCXX/warn-shadow.cpp +++ test/SemaCXX/warn-shadow.cpp @@ -225,7 +225,7 @@ namespace PR34120 { struct A { - int B; // expected-note {{declared here}} + int B; // expected-note 2 {{declared here}} }; class C : public A { @@ -233,8 +233,13 @@ void E() { extern void f(int B); // Ok } + void F(int B); // Ok, declaration; not definition. + void G(int B); }; +void C::G(int B) { // expected-warning {{parameter 'B' shadows member inherited from type 'A'}} +} + class Private { int B; };