John McCall | a369a95 | 2010-03-20 04:12:52 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s |
John McCall | 9a8cb8d | 2010-03-16 21:50:59 +0000 | [diff] [blame] | 2 | |
John McCall | a369a95 | 2010-03-20 04:12:52 +0000 | [diff] [blame] | 3 | int i; // expected-note 3 {{previous declaration is here}} |
John McCall | 9a8cb8d | 2010-03-16 21:50:59 +0000 | [diff] [blame] | 4 | |
| 5 | void foo() { |
| 6 | int pass1; |
| 7 | int i; // expected-warning {{declaration shadows a variable in the global scope}} \ |
| 8 | // expected-note {{previous declaration is here}} |
| 9 | { |
| 10 | int pass2; |
| 11 | int i; // expected-warning {{declaration shadows a local variable}} \ |
| 12 | // expected-note {{previous declaration is here}} |
| 13 | { |
| 14 | int pass3; |
| 15 | int i; // expected-warning {{declaration shadows a local variable}} |
| 16 | } |
| 17 | } |
| 18 | |
Douglas Gregor | c48c916 | 2010-03-17 16:03:44 +0000 | [diff] [blame] | 19 | int sin; // okay; 'sin' has not been declared, even though it's a builtin. |
John McCall | 9a8cb8d | 2010-03-16 21:50:59 +0000 | [diff] [blame] | 20 | } |
John McCall | a369a95 | 2010-03-20 04:12:52 +0000 | [diff] [blame] | 21 | |
| 22 | // <rdar://problem/7677531> |
| 23 | void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \ |
| 24 | // expected-note{{previous declaration is here}} |
| 25 | { |
| 26 | int i; // expected-warning {{declaration shadows a local variable}} \ |
| 27 | // expected-note{{previous declaration is here}} |
| 28 | |
| 29 | (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}} |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | struct test2 { |
| 35 | int i; |
| 36 | }; |
| 37 | |
| 38 | void test3(void) { |
| 39 | struct test4 { |
| 40 | int i; |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}} |
| 45 | } |
John McCall | 053f4bd | 2010-03-22 09:20:08 +0000 | [diff] [blame] | 46 | |
| 47 | // Don't warn about shadowing for function declarations. |
| 48 | void test5(int i); |
| 49 | void test6(void (*f)(int i)) {} |
| 50 | void test7(void *context, void (*callback)(void *context)) {} |