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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits