1 // RUN: %clang_cc1 %s -Wno-pointer-to-int-cast -verify -fsyntax-only -ffreestanding
6 typedef void (* fp
)(void);
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]);
30 int b
[10] = a
; // expected-error {{array initializer must be an initializer list}}
31 int +; // expected-error {{expected identifier or '('}}
33 struct union_crash u
= { .d
= 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}}
43 int cdiff_cmd_open(void);
44 struct cdiff_cmd commands
[] = {
45 {"OPEN", 1, &cdiff_cmd_open
}
49 static struct { int z
; } s
[2];
56 static short *bp
= &b
; // expected-error {{initializer element is not a compile-time constant}}
62 typedef const _Bool cbool
;
63 _Bool pbool1
= (void *) 0;
64 cbool pbool2
= &pbool
;
69 union { float f
; unsigned u
; } u
= { 1.0f
};
71 int f3(int x
) { return x
; }
72 typedef void (*vfunc
)(void);
73 void *bar
= (vfunc
) f3
;
79 int sym_fw1a_scr
[] = {
80 ((int)(&((struct sym_reg
*)0)->nc_gpreg
)) & 0,
81 8 * ((int)(&((struct sym_reg
*)0)->nc_gpreg
))
85 struct s1 s2
= { // expected-error {{variable has incomplete type 'struct s1'}} \
86 // expected-note {{forward declaration of 'struct s1'}}
87 .a
= sizeof(struct s3
), // expected-error {{invalid application of 'sizeof'}} \
88 // expected-note{{forward declaration of 'struct s3'}}
89 .b
= bogus
// expected-error {{use of undeclared identifier 'bogus'}}
95 typedef struct { } empty
;
102 st st1
= { .i2
= 1 };
115 struct foo2 bar2
[] = {
119 struct foo2 bar3
= { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
120 #pragma clang diagnostic push
121 #pragma clang diagnostic ignored "-Wexcess-initializers"
122 struct foo2 bar3_silent
= {1, 2};
123 #pragma clang diagnostic pop
125 int* ptest1
= __builtin_choose_expr(1, (int*)0, (int*)0);
127 typedef int32_t ivector4
__attribute((vector_size(16)));
128 ivector4 vtest1
= 1 ? (ivector4
){1} : (ivector4
){1};
129 ivector4 vtest2
= __builtin_choose_expr(1, (ivector4
){1}, (ivector4
){1});
131 uintptr_t ptrasintadd1
= (uintptr_t)&a
- 4;
132 uintptr_t ptrasintadd2
= (uintptr_t)&a
+ 4;
133 uintptr_t ptrasintadd3
= 4 + (uintptr_t)&a
;
136 const wchar_t widestr
[] = L
"asdf";
139 const double pr5447
= (0.05 < -1.0) ? -1.0 : 0.0499878;
143 // None of these are constant initializers, but we implement GCC's old
144 // behaviour of accepting bar and zed but not foo. GCC's behaviour was
145 // changed in 2007 (rev 122551), so we should be able to change too one
147 int PR4386_bar(void);
148 int PR4386_foo(void) __attribute((weak
));
149 int PR4386_zed(void);
151 int PR4386_a
= ((void *) PR4386_bar
) != 0;
152 int PR4386_b
= ((void *) PR4386_foo
) != 0; // expected-error{{initializer element is not a compile-time constant}}
153 int PR4386_c
= ((void *) PR4386_zed
) != 0;
154 int PR4386_zed(void) __attribute((weak
));
156 // (derived from SPEC vortex benchmark)
157 typedef char strty
[10];
158 struct vortexstruct
{ strty s
; };
159 struct vortexstruct vortexvar
= { "asdf" };
161 typedef struct { uintptr_t x
: 2; } StructWithBitfield
;
162 StructWithBitfield bitfieldvar
= { (uintptr_t)&bitfieldvar
}; // expected-error {{initializer element is not a compile-time constant}}
169 struct PR4517_foo foo
;
171 const struct PR4517_foo my_foo
= {.x
= 42};
172 struct PR4517_bar my_bar
= {
173 .foo
= my_foo
, // no-warning
175 struct PR4517_bar my_bar2
= (struct PR4517_bar
){
176 .foo
= my_foo
, // no-warning
178 struct PR4517_bar my_bar3
= {
179 my_foo
, // no-warning
181 struct PR4517_bar my_bar4
= (struct PR4517_bar
){
184 extern const struct PR4517_foo my_foo2
;
185 struct PR4517_bar my_bar5
= {
186 .foo
= my_foo2
, // expected-error {{initializer element is not a compile-time constant}}
188 const struct PR4517_foo my_foo3
= {.x
= my_foo
.x
};
189 int PR4517_a
[2] = {0, 1};
190 const int PR4517_ca
[2] = {0, 1};
192 const int PR4517_idxc
= 1;
193 int PR4517_x1
= PR4517_a
[PR4517_idx
]; // expected-error {{initializer element is not a compile-time constant}}
194 int PR4517_x2
= PR4517_a
[PR4517_idxc
]; // expected-error {{initializer element is not a compile-time constant}}
195 int PR4517_x3
= PR4517_a
[0]; // expected-error {{initializer element is not a compile-time constant}}
196 int PR4517_y1
= PR4517_ca
[PR4517_idx
]; // expected-error {{initializer element is not a compile-time constant}}
197 int PR4517_y2
= PR4517_ca
[PR4517_idxc
]; // no-warning
198 int PR4517_y3
= PR4517_ca
[0]; // no-warning
203 const union PR4517_u u1
= {4.0f
};
204 const union PR4517_u u2
= u1
; // no-warning
205 const union PR4517_u u3
= {u1
.y
}; // expected-error {{initializer element is not a compile-time constant}}