]> granicus.if.org Git - clang/commit
Fix -Wshadow false positives with function-local classes.
authorAlexander Kornienko <alexfh@google.com>
Mon, 31 Jul 2017 15:21:26 +0000 (15:21 +0000)
committerAlexander Kornienko <alexfh@google.com>
Mon, 31 Jul 2017 15:21:26 +0000 (15:21 +0000)
commit86e9daf19ba45dd6f133d0df160c8f464f27a7d8
treece2dcbdce55505af7fb40cbbb65a2290de212eeb
parentc38987d1ea4e93148913cb26d8a1b556305523c7
Fix -Wshadow false positives with function-local classes.

Summary:
Fixes http://llvm.org/PR33947.

https://godbolt.org/g/54XRMT

void f(int a) {
  struct A {
    void g(int a) {}
    A() { int a; }
  };
}

3 : <source>:3:16: warning: declaration shadows a local variable [-Wshadow]
    void g(int a) {}
               ^
1 : <source>:1:12: note: previous declaration is here
void f(int a) {
           ^
4 : <source>:4:15: warning: declaration shadows a local variable [-Wshadow]
    A() { int a; }
              ^
1 : <source>:1:12: note: previous declaration is here
void f(int a) {
           ^
2 warnings generated.

The local variable `a` of the function `f` can't be accessed from a method of
the function-local class A, thus no shadowing occurs and no diagnostic is
needed.

Reviewers: rnk, rsmith, arphaman, Quuxplusone

Reviewed By: rnk, Quuxplusone

Subscribers: Quuxplusone, cfe-commits

Differential Revision: https://reviews.llvm.org/D35941

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309569 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-shadow.cpp