From: Stephan Bergmann Date: Wed, 5 Apr 2017 08:36:58 +0000 (+0000) Subject: Don't issue a warning if the shadowing declaration is in a class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2971257756c10c405801c073a009ed06f1a6ad70;p=clang Don't issue a warning if the shadowing declaration is in a class Follow-up to r299363 "Enhance -Wshadow to warn when shadowing typedefs or type aliases". Patch by Ahmed Asadi. Differential Revision: https://reviews.llvm.org/D31235 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299522 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7659fba14a..c0a1015840 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6744,6 +6744,10 @@ NamedDecl *Sema::getShadowedDeclaration(const VarDecl *D, /// 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; diff --git a/test/SemaCXX/warn-shadow.cpp b/test/SemaCXX/warn-shadow.cpp index 110e53f2bb..0b84ef50ca 100644 --- a/test/SemaCXX/warn-shadow.cpp +++ b/test/SemaCXX/warn-shadow.cpp @@ -87,6 +87,16 @@ class A { } }; +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, class B : A { int data;