]> granicus.if.org Git - clang/commitdiff
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299522 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7659fba14a3287b22b6a74416399b9d7e3164408..c0a1015840531ff846df6e9fc9efb4affa29bc72 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 110e53f2bbe9c6ef4d9f4ca0b5dc2f3e220232c5..0b84ef50caa1425e3b49cdafa0dc1a8e22cc4a16 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;