Allow resolving headers from a PCH even after headers+PCH were moved to another path.
[clang.git] / test / Sema / init.c
blobf8110079d0eb47fd44479d714fc83457c04eaaa3
1 // RUN: %clang_cc1 %s -verify -fsyntax-only -ffreestanding
3 #include <stddef.h>
4 #include <stdint.h>
6 typedef void (* fp)(void);
7 void foo(void);
9 // PR clang/3377
10 fp a[(short int)1] = { foo };
12 int myArray[5] = {1, 2, 3, 4, 5};
13 int *myPointer2 = myArray;
14 int *myPointer = &(myArray[2]);
17 extern int x;
18 void *g = &x;
19 int *h = &x;
21 int test() {
22 int a[10];
23 int b[10] = a; // expected-error {{array initializer must be an initializer list}}
24 int +; // expected-error {{expected identifier or '('}}
28 // PR2050
29 struct cdiff_cmd {
30 const char *name;
31 unsigned short argc;
32 int (*handler)();
34 int cdiff_cmd_open();
35 struct cdiff_cmd commands[] = {
36 {"OPEN", 1, &cdiff_cmd_open }
39 // PR2348
40 static struct { int z; } s[2];
41 int *t = &(*s).z;
43 // PR2349
44 short *a2(void)
46 short int b;
47 static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
49 return bp;
52 int pbool(void) {
53 typedef const _Bool cbool;
54 _Bool pbool1 = (void *) 0;
55 cbool pbool2 = &pbool;
56 return pbool2;
60 // rdar://5870981
61 union { float f; unsigned u; } u = { 1.0f };
63 // rdar://6156694
64 int f3(int x) { return x; }
65 typedef void (*vfunc)(void);
66 void *bar = (vfunc) f3;
68 // PR2747
69 struct sym_reg {
70 char nc_gpreg;
72 int sym_fw1a_scr[] = {
73 ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
74 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
77 // PR3001
78 struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \
79 // expected-note {{forward declaration of 'struct s1'}}
80 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
81 // expected-note{{forward declaration of 'struct s3'}}
82 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
85 // PR3382
86 char t[] = ("Hello");
88 // <rdar://problem/6094855>
89 typedef struct { } empty;
91 typedef struct {
92 empty e;
93 int i2;
94 } st;
96 st st1 = { .i2 = 1 };
98 // <rdar://problem/6096826>
99 struct {
100 int a;
101 int z[2];
102 } y = { .z = {} };
104 int bbb[10];
106 struct foo2 {
107 uintptr_t a;
110 struct foo2 bar2[] = {
111 { (intptr_t)bbb }
114 struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
116 int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);
118 typedef int32_t ivector4 __attribute((vector_size(16)));
119 ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1};
120 ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1});
122 uintptr_t ptrasintadd1 = (uintptr_t)&a - 4;
123 uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;
124 uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a;
126 // PR4285
127 const wchar_t widestr[] = L"asdf";
129 // PR5447
130 const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;
132 // PR4386
134 // None of these are constant initializers, but we implement GCC's old
135 // behaviour of accepting bar and zed but not foo. GCC's behaviour was
136 // changed in 2007 (rev 122551), so we should be able to change too one
137 // day.
138 int PR4386_bar();
139 int PR4386_foo() __attribute((weak));
140 int PR4386_zed();
142 int PR4386_a = ((void *) PR4386_bar) != 0;
143 int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
144 int PR4386_c = ((void *) PR4386_zed) != 0;
145 int PR4386_zed() __attribute((weak));