[PATCH] D55321: Do not check for parameters shadowing fields in function declarations
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 5 06:47:23 PST 2018
aaron.ballman updated this revision to Diff 176807.
aaron.ballman added a comment.
Added a test with an out-of-line definition.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55321/new/
https://reviews.llvm.org/D55321
Files:
lib/Sema/SemaChecking.cpp
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
@@ -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;
};
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<CXXRecordDecl>(CurContext))
- CheckShadowInheritedFields(DNI.getLoc(), DNI.getName(), RD,
- /*DeclIsField*/ false);
- }
}
// Temporarily put parameter variables in the translation unit, not
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<CXXRecordDecl>(DC->getParent()))
+ CheckShadowInheritedFields(Param->getLocation(), Param->getDeclName(),
+ RD, /*DeclIsField*/ false);
+ }
+ }
}
return HasInvalidParm;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55321.176807.patch
Type: text/x-patch
Size: 2253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181205/0acdad0e/attachment.bin>
More information about the cfe-commits
mailing list