Do not check for parameters shadowing fields in function declarations.

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
This commit is contained in:
Aaron Ballman 2018-12-05 18:56:57 +00:00
parent 83efe2f1f6
commit c3463f6ba8
3 changed files with 19 additions and 9 deletions

View File

@ -12141,6 +12141,18 @@ bool Sema::CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters,
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;

View File

@ -12427,13 +12427,6 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
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

View File

@ -201,7 +201,7 @@ void avoidWarningWhenRedefining(int b) { // expected-note {{previous definition
typedef char l; // no warning or error.
typedef char n; // no warning or error.
typedef char n; // no warning or error.
typedef char n; // no warning or error.
using n=char; // no warning or error.
}
@ -225,7 +225,7 @@ void f(int a) {
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 @@ class C : public A {
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;
};