1a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall// RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s
29a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall
3a369a95f756b6190b5611ff4118b4cabfc704dc0John McCallint i;          // expected-note 3 {{previous declaration is here}}
49a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall
59a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCallvoid foo() {
69a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall  int pass1;
79a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall  int i;        // expected-warning {{declaration shadows a variable in the global scope}} \
89a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall                // expected-note {{previous declaration is here}}
99a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall  {
109a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall    int pass2;
119a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall    int i;      // expected-warning {{declaration shadows a local variable}} \
129a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall                // expected-note {{previous declaration is here}}
139a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall    {
149a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall      int pass3;
159a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall      int i;    // expected-warning {{declaration shadows a local variable}}
169a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall    }
179a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall  }
189a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall
19c48c916b8cebba954429715f15bd5b5e8e4d4574Douglas Gregor  int sin; // okay; 'sin' has not been declared, even though it's a builtin.
209a8cb8d4bdbb3eaf6e8cd8cb3e47b343694c01f8John McCall}
21a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall
22a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall// <rdar://problem/7677531>
23a369a95f756b6190b5611ff4118b4cabfc704dc0John McCallvoid (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \
24a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall                                 // expected-note{{previous declaration is here}}
25a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall  {
26a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall    int i; // expected-warning {{declaration shadows a local variable}} \
27a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall           // expected-note{{previous declaration is here}}
28a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall
29a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall    (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}}
30a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall  }
31a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall};
32a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall
33a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall
34a369a95f756b6190b5611ff4118b4cabfc704dc0John McCallstruct test2 {
35a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall  int i;
36a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall};
37a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall
38a369a95f756b6190b5611ff4118b4cabfc704dc0John McCallvoid test3(void) {
39a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall  struct test4 {
40a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall    int i;
41a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall  };
42a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall}
43a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall
44a369a95f756b6190b5611ff4118b4cabfc704dc0John McCallvoid test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}}
45a369a95f756b6190b5611ff4118b4cabfc704dc0John McCall}
46053f4bddcb10bd3b17cd6a66fe52e265498603edJohn McCall
47053f4bddcb10bd3b17cd6a66fe52e265498603edJohn McCall// Don't warn about shadowing for function declarations.
48053f4bddcb10bd3b17cd6a66fe52e265498603edJohn McCallvoid test5(int i);
49053f4bddcb10bd3b17cd6a66fe52e265498603edJohn McCallvoid test6(void (*f)(int i)) {}
50053f4bddcb10bd3b17cd6a66fe52e265498603edJohn McCallvoid test7(void *context, void (*callback)(void *context)) {}
516df96e0756f62edc859d649069daf523536c4221Argyrios Kyrtzidis
5249a61727986332f2eba61fb2657800d76c5a4bb9Argyrios Kyrtzidisextern int bob; // expected-note {{previous declaration is here}}
5349a61727986332f2eba61fb2657800d76c5a4bb9Argyrios Kyrtzidis
546df96e0756f62edc859d649069daf523536c4221Argyrios Kyrtzidis// rdar://8883302
556df96e0756f62edc859d649069daf523536c4221Argyrios Kyrtzidisvoid rdar8883302() {
566df96e0756f62edc859d649069daf523536c4221Argyrios Kyrtzidis  extern int bob; // don't warn for shadowing.
576df96e0756f62edc859d649069daf523536c4221Argyrios Kyrtzidis}
5849a61727986332f2eba61fb2657800d76c5a4bb9Argyrios Kyrtzidis
5949a61727986332f2eba61fb2657800d76c5a4bb9Argyrios Kyrtzidisvoid test8() {
6049a61727986332f2eba61fb2657800d76c5a4bb9Argyrios Kyrtzidis  int bob; // expected-warning {{declaration shadows a variable in the global scope}}
6149a61727986332f2eba61fb2657800d76c5a4bb9Argyrios Kyrtzidis}
62