1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wshadow %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc int i; // expected-note 3 {{previous declaration is here}} 4*f4a2713aSLionel Sambuc foo()5*f4a2713aSLionel Sambucvoid foo() { 6*f4a2713aSLionel Sambuc int pass1; 7*f4a2713aSLionel Sambuc int i; // expected-warning {{declaration shadows a variable in the global scope}} \ 8*f4a2713aSLionel Sambuc // expected-note {{previous declaration is here}} 9*f4a2713aSLionel Sambuc { 10*f4a2713aSLionel Sambuc int pass2; 11*f4a2713aSLionel Sambuc int i; // expected-warning {{declaration shadows a local variable}} \ 12*f4a2713aSLionel Sambuc // expected-note {{previous declaration is here}} 13*f4a2713aSLionel Sambuc { 14*f4a2713aSLionel Sambuc int pass3; 15*f4a2713aSLionel Sambuc int i; // expected-warning {{declaration shadows a local variable}} 16*f4a2713aSLionel Sambuc } 17*f4a2713aSLionel Sambuc } 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc int sin; // okay; 'sin' has not been declared, even though it's a builtin. 20*f4a2713aSLionel Sambuc } 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc // <rdar://problem/7677531> 23*f4a2713aSLionel Sambuc void (^test1)(int) = ^(int i) { // expected-warning {{declaration shadows a variable in the global scope}} \ 24*f4a2713aSLionel Sambuc // expected-note{{previous declaration is here}} 25*f4a2713aSLionel Sambuc { 26*f4a2713aSLionel Sambuc int i; // expected-warning {{declaration shadows a local variable}} \ 27*f4a2713aSLionel Sambuc // expected-note{{previous declaration is here}} 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc (^(int i) { return i; })(i); //expected-warning {{declaration shadows a local variable}} 30*f4a2713aSLionel Sambuc } 31*f4a2713aSLionel Sambuc }; 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc struct test2 { 35*f4a2713aSLionel Sambuc int i; 36*f4a2713aSLionel Sambuc }; 37*f4a2713aSLionel Sambuc test3(void)38*f4a2713aSLionel Sambucvoid test3(void) { 39*f4a2713aSLionel Sambuc struct test4 { 40*f4a2713aSLionel Sambuc int i; 41*f4a2713aSLionel Sambuc }; 42*f4a2713aSLionel Sambuc } 43*f4a2713aSLionel Sambuc test4(int i)44*f4a2713aSLionel Sambucvoid test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}} 45*f4a2713aSLionel Sambuc } 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc // Don't warn about shadowing for function declarations. 48*f4a2713aSLionel Sambuc void test5(int i); test6(void (* f)(int i))49*f4a2713aSLionel Sambucvoid test6(void (*f)(int i)) {} test7(void * context,void (* callback)(void * context))50*f4a2713aSLionel Sambucvoid test7(void *context, void (*callback)(void *context)) {} 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc extern int bob; // expected-note {{previous declaration is here}} 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambuc // rdar://8883302 rdar8883302()55*f4a2713aSLionel Sambucvoid rdar8883302() { 56*f4a2713aSLionel Sambuc extern int bob; // don't warn for shadowing. 57*f4a2713aSLionel Sambuc } 58*f4a2713aSLionel Sambuc test8()59*f4a2713aSLionel Sambucvoid test8() { 60*f4a2713aSLionel Sambuc int bob; // expected-warning {{declaration shadows a variable in the global scope}} 61*f4a2713aSLionel Sambuc } 62