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