1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s 2*67e74705SXin Li 3*67e74705SXin Li // rdar: // 8125274 4*67e74705SXin Li static int a16[]; // expected-warning {{tentative array definition assumed to have one element}} 5*67e74705SXin Li f16(void)6*67e74705SXin Livoid f16(void) { 7*67e74705SXin Li extern int a16[]; 8*67e74705SXin Li } 9*67e74705SXin Li 10*67e74705SXin Li 11*67e74705SXin Li // PR10013: Scope of extern declarations extend past enclosing block 12*67e74705SXin Li extern int PR10013_x; PR10013(void)13*67e74705SXin Liint PR10013(void) { 14*67e74705SXin Li int *PR10013_x = 0; 15*67e74705SXin Li { 16*67e74705SXin Li extern int PR10013_x; 17*67e74705SXin Li extern int PR10013_x; 18*67e74705SXin Li } 19*67e74705SXin Li 20*67e74705SXin Li return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}} 21*67e74705SXin Li } 22*67e74705SXin Li 23*67e74705SXin Li static int test1_a[]; // expected-warning {{tentative array definition assumed to have one element}} 24*67e74705SXin Li extern int test1_a[]; 25*67e74705SXin Li 26*67e74705SXin Li // rdar://13535367 test2declarer()27*67e74705SXin Livoid test2declarer() { extern int test2_array[100]; } 28*67e74705SXin Li extern int test2_array[]; 29*67e74705SXin Li int test2v = sizeof(test2_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} 30*67e74705SXin Li test3declarer()31*67e74705SXin Livoid test3declarer() { 32*67e74705SXin Li { extern int test3_array[100]; } 33*67e74705SXin Li extern int test3_array[]; 34*67e74705SXin Li int x = sizeof(test3_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} 35*67e74705SXin Li } 36*67e74705SXin Li test4()37*67e74705SXin Livoid test4() { 38*67e74705SXin Li extern int test4_array[]; 39*67e74705SXin Li { 40*67e74705SXin Li extern int test4_array[100]; 41*67e74705SXin Li int x = sizeof(test4_array); // fine 42*67e74705SXin Li } 43*67e74705SXin Li int x = sizeof(test4_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} 44*67e74705SXin Li } 45*67e74705SXin Li 46*67e74705SXin Li // Test that invalid local extern declarations of library 47*67e74705SXin Li // builtins behave reasonably. 48*67e74705SXin Li extern void abort(void); // expected-note 2 {{previous declaration is here}} 49*67e74705SXin Li extern float *calloc(); // expected-warning {{incompatible redeclaration of library function}} expected-note {{is a builtin}} expected-note 2 {{previous declaration is here}} test5a()50*67e74705SXin Livoid test5a() { 51*67e74705SXin Li int abort(); // expected-error {{conflicting types}} 52*67e74705SXin Li float *malloc(); // expected-warning {{incompatible redeclaration of library function}} expected-note 2 {{is a builtin}} 53*67e74705SXin Li int *calloc(); // expected-error {{conflicting types}} 54*67e74705SXin Li } test5b()55*67e74705SXin Livoid test5b() { 56*67e74705SXin Li int abort(); // expected-error {{conflicting types}} 57*67e74705SXin Li float *malloc(); // expected-warning {{incompatible redeclaration of library function}} 58*67e74705SXin Li int *calloc(); // expected-error {{conflicting types}} 59*67e74705SXin Li } test5c()60*67e74705SXin Livoid test5c() { 61*67e74705SXin Li void (*_abort)(void) = &abort; 62*67e74705SXin Li void *(*_malloc)() = &malloc; 63*67e74705SXin Li float *(*_calloc)() = &calloc; 64*67e74705SXin Li } 65*67e74705SXin Li test6()66*67e74705SXin Livoid test6() { 67*67e74705SXin Li extern int test6_array1[100]; 68*67e74705SXin Li extern int test6_array2[100]; 69*67e74705SXin Li void test6_fn1(int*); 70*67e74705SXin Li void test6_fn2(int*); 71*67e74705SXin Li { 72*67e74705SXin Li // Types are only merged from visible declarations. 73*67e74705SXin Li char test6_array2; 74*67e74705SXin Li char test6_fn2; 75*67e74705SXin Li { 76*67e74705SXin Li extern int test6_array1[]; 77*67e74705SXin Li extern int test6_array2[]; 78*67e74705SXin Li (void)sizeof(test6_array1); // ok 79*67e74705SXin Li (void)sizeof(test6_array2); // expected-error {{incomplete type}} 80*67e74705SXin Li 81*67e74705SXin Li void test6_fn1(); 82*67e74705SXin Li void test6_fn2(); 83*67e74705SXin Li test6_fn1(1.2); // expected-error {{passing 'double' to parameter of incompatible type 'int *'}} 84*67e74705SXin Li // FIXME: This is valid, but we should warn on it. 85*67e74705SXin Li test6_fn2(1.2); 86*67e74705SXin Li } 87*67e74705SXin Li } 88*67e74705SXin Li } 89