1 // RUN: %clang_cc1 -verify -fsyntax-only -Wshadow-all %s
2 
3 namespace {
4   int i; // expected-note {{previous declaration is here}}
5 }
6 
7 namespace one {
8 namespace two {
9   int j; // expected-note {{previous declaration is here}}
10 }
11 }
12 
13 namespace xx {
14   int m;
15 }
16 namespace yy {
17   int m;
18 }
19 
20 using namespace one::two;
21 using namespace xx;
22 using namespace yy;
23 
24 void foo() {
25   int i; // expected-warning {{declaration shadows a variable in namespace '(anonymous)'}}
26   int j; // expected-warning {{declaration shadows a variable in namespace 'one::two'}}
27   int m;
28 }
29 
30 class A {
31   static int data; // expected-note {{previous declaration}}
32   // expected-note@+1 {{previous declaration}}
33   int field;
34   int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
35 
36   // The initialization is safe, but the modifications are not.
37   A(int f1, int f2, int f3, int f4) // expected-note-re 4 {{variable 'f{{[0-4]}}' is declared here}}
38 	  : f1(f1) {
39     f1 = 3; // expected-warning {{modifying constructor parameter 'f1' that shadows a field of 'A'}}
40     f1 = 4; // one warning per shadow
41     f2++; // expected-warning {{modifying constructor parameter 'f2' that shadows a field of 'A'}}
42     --f3; // expected-warning {{modifying constructor parameter 'f3' that shadows a field of 'A'}}
43     f4 += 2; // expected-warning {{modifying constructor parameter 'f4' that shadows a field of 'A'}}
44   }
45 
46   // The initialization is safe, but the modifications are not.
47   // expected-warning-re@+1 4 {{constructor parameter 'f{{[0-4]}}' shadows the field 'f{{[0-9]}}' of 'A'}}
48   A(int f1, int f2, int f3, int f4, double overload_dummy) {}
49 
50   void test() {
51     char *field; // expected-warning {{declaration shadows a field of 'A'}}
52     char *data; // expected-warning {{declaration shadows a static data member of 'A'}}
53   }
54 };
55 
56 // TODO: this should warn, <rdar://problem/5018057>
57 class B : A {
58   int data;
59   static int field;
60 };
61 
62 // rdar://8900456
63 namespace rdar8900456 {
64 struct Foo {
65   static void Baz();
66 private:
67   int Bar;
68 };
69 
70 void Foo::Baz() {
71   double Bar = 12; // Don't warn.
72 }
73 }
74 
75 // http://llvm.org/PR9160
76 namespace PR9160 {
77 struct V {
78   V(int);
79 };
80 struct S {
81   V v;
82   static void m() {
83     if (1) {
84       V v(0);
85     }
86   }
87 };
88 }
89 
90 extern int bob; // expected-note {{previous declaration is here}}
91 
92 // rdar://8883302
93 void rdar8883302() {
94   extern int bob; // don't warn for shadowing.
95 }
96 
97 void test8() {
98   int bob; // expected-warning {{declaration shadows a variable in the global namespace}}
99 }
100