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