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