[PATCH] D31235: Enhance -Wshadow to warn when shadowing typedefs or type aliases
Ahmed Asadi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 22:55:46 PDT 2017
ahmedasadi updated this revision to Diff 94007.
ahmedasadi added a comment.
Updated diff to address Eric's comment - it's best not to issue a warning if the shadowing declaration is part of a class (this is what GCC currently does).
I will need someone to commit this new patch for me.
https://reviews.llvm.org/D31235
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
@@ -87,6 +87,16 @@
}
};
+struct path {
+ using value_type = char;
+ typedef char value_type2;
+ struct iterator {
+ using value_type = path; // no warning
+ typedef path value_type2; // no warning
+ };
+};
+
+
// TODO: this should warn, <rdar://problem/5018057>
class B : A {
int data;
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6742,6 +6742,10 @@
/// if it doesn't shadow any declaration or shadowing warnings are disabled.
NamedDecl *Sema::getShadowedDeclaration(const TypedefNameDecl *D,
const LookupResult &R) {
+ // Don't warn if typedef declaration is part of a class
+ if (D->getDeclContext()->isRecord())
+ return nullptr;
+
if (!shouldWarnIfShadowedDecl(Diags, R))
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31235.94007.patch
Type: text/x-patch
Size: 1051 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170404/64be46ee/attachment-0001.bin>
More information about the cfe-commits
mailing list