[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / extern-redecl.c
blob3a9720986137ca0f7bda6bbc9783f73d8b499d8a
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-strict-prototypes %s
3 static int a16[]; // expected-warning {{tentative array definition assumed to have one element}}
5 void f16(void) {
6 extern int a16[];
10 // PR10013: Scope of extern declarations extend past enclosing block
11 extern int PR10013_x;
12 int PR10013(void) {
13 int *PR10013_x = 0;
15 extern int PR10013_x;
16 extern int PR10013_x;
19 return PR10013_x; // expected-error{{incompatible pointer to integer conversion}}
22 static int test1_a[]; // expected-warning {{tentative array definition assumed to have one element}}
23 extern int test1_a[];
25 void test2declarer(void) { extern int test2_array[100]; }
26 extern int test2_array[];
27 int test2v = sizeof(test2_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
29 void 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[]'}}
35 void test4(void) {
36 extern int test4_array[];
38 extern int test4_array[100];
39 int x = sizeof(test4_array); // fine
41 int x = sizeof(test4_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
44 // Test that invalid local extern declarations of library
45 // builtins behave reasonably.
46 extern void abort(void); // expected-note 2 {{previous declaration is here}}
47 extern float *calloc(void); // expected-warning {{incompatible redeclaration of library function}} expected-note {{is a builtin}} expected-note 2 {{previous declaration is here}}
48 void 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}}
53 void 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}}
58 void test5c(void) {
59 void (*_abort)(void) = &abort;
60 void *(*_malloc)() = &malloc;
61 float *(*_calloc)() = &calloc;
64 void test6(void) {
65 extern int test6_array1[100];
66 extern int test6_array2[100];
67 void test6_fn1(int*);
68 void test6_fn2(int*);
70 // Types are only merged from visible declarations.
71 char test6_array2;
72 char test6_fn2;
74 extern int test6_array1[];
75 extern int test6_array2[];
76 (void)sizeof(test6_array1); // ok
77 (void)sizeof(test6_array2); // expected-error {{incomplete type}}
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);