We would issue a false-positive diagnostic for parameters in function declarations shadowing fields; we now only issue the diagnostic on a function definition instead.
llvm-svn: 348400
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<CXXRecordDecl>(DC->getParent()))
+ CheckShadowInheritedFields(Param->getLocation(), Param->getDeclName(),
+ RD, /*DeclIsField*/ false);
+ }
+ }
}
return HasInvalidParm;
D.setInvalidType(true);
}
}
-
- if (LangOpts.CPlusPlus) {
- DeclarationNameInfo DNI = GetNameForDeclarator(D);
- if (auto *RD = dyn_cast<CXXRecordDecl>(CurContext))
- CheckShadowInheritedFields(DNI.getLoc(), DNI.getName(), RD,
- /*DeclIsField*/ false);
- }
}
// Temporarily put parameter variables in the translation unit, not
typedef char l; // no warning or error.\r
typedef char n; // no warning or error.
- typedef char n; // no warning or error.\r
+ typedef char n; // no warning or error.
using n=char; // no warning or error.\r
}\r
\r
namespace PR34120 {\r
struct A {\r
- int B; // expected-note {{declared here}}\r
+ int B; // expected-note 2 {{declared here}}\r
};\r
\r
class C : public A {\r
void E() {\r
extern void f(int B); // Ok\r
}\r
+ void F(int B); // Ok, declaration; not definition.\r
+ void G(int B);\r
};\r
\r
+void C::G(int B) { // expected-warning {{parameter 'B' shadows member inherited from type 'A'}}\r
+}\r
+\r
class Private {\r
int B;\r
};\r