Don't issue a warning if the shadowing declaration is in a class
authorStephan Bergmann <sbergman@redhat.com>
Wed, 5 Apr 2017 08:36:58 +0000 (08:36 +0000)
committerStephan Bergmann <sbergman@redhat.com>
Wed, 5 Apr 2017 08:36:58 +0000 (08:36 +0000)
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

llvm-svn: 299522

clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/warn-shadow.cpp

index 7659fba..c0a1015 100644 (file)
@@ -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;
 
index 110e53f..0b84ef5 100644 (file)
@@ -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, <rdar://problem/5018057>
 class B : A {
   int data;