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
;
70 union { float f
; unsigned u
; } u
= { 1.0f
};
73 int f3(int x
) { return x
; }
74 typedef void (*vfunc
)(void);
75 void *bar
= (vfunc
) f3
;
81 int sym_fw1a_scr
[] = {
82 ((int)(&((struct sym_reg
*)0)->nc_gpreg
)) & 0,
83 8 * ((int)(&((struct sym_reg
*)0)->nc_gpreg
))
87 struct s1 s2
= { // expected-error {{variable has incomplete type 'struct s1'}} \
88 // expected-note {{forward declaration of 'struct s1'}}
89 .a
= sizeof(struct s3
), // expected-error {{invalid application of 'sizeof'}} \
90 // expected-note{{forward declaration of 'struct s3'}}
91 .b
= bogus
// expected-error {{use of undeclared identifier 'bogus'}}
97 // <rdar://problem/6094855>
98 typedef struct { } empty
;
105 st st1
= { .i2
= 1 };
107 // <rdar://problem/6096826>
119 struct foo2 bar2
[] = {
123 struct foo2 bar3
= { 1, 2 }; // expected-warning{{excess elements in struct initializer}}
124 #pragma clang diagnostic push
125 #pragma clang diagnostic ignored "-Wexcess-initializers"
126 struct foo2 bar3_silent
= {1, 2};
127 #pragma clang diagnostic pop
129 int* ptest1
= __builtin_choose_expr(1, (int*)0, (int*)0);
131 typedef int32_t ivector4
__attribute((vector_size(16)));
132 ivector4 vtest1
= 1 ? (ivector4
){1} : (ivector4
){1};
133 ivector4 vtest2
= __builtin_choose_expr(1, (ivector4
){1}, (ivector4
){1});
135 uintptr_t ptrasintadd1
= (uintptr_t)&a
- 4;
136 uintptr_t ptrasintadd2
= (uintptr_t)&a
+ 4;
137 uintptr_t ptrasintadd3
= 4 + (uintptr_t)&a
;
140 const wchar_t widestr
[] = L
"asdf";
143 const double pr5447
= (0.05 < -1.0) ? -1.0 : 0.0499878;
147 // None of these are constant initializers, but we implement GCC's old
148 // behaviour of accepting bar and zed but not foo. GCC's behaviour was
149 // changed in 2007 (rev 122551), so we should be able to change too one
151 int PR4386_bar(void);
152 int PR4386_foo(void) __attribute((weak
));
153 int PR4386_zed(void);
155 int PR4386_a
= ((void *) PR4386_bar
) != 0;
156 int PR4386_b
= ((void *) PR4386_foo
) != 0; // expected-error{{initializer element is not a compile-time constant}}
157 int PR4386_c
= ((void *) PR4386_zed
) != 0;
158 int PR4386_zed(void) __attribute((weak
));
160 // <rdar://problem/10185490> (derived from SPEC vortex benchmark)
161 typedef char strty
[10];
162 struct vortexstruct
{ strty s
; };
163 struct vortexstruct vortexvar
= { "asdf" };
165 typedef struct { uintptr_t x
: 2; } StructWithBitfield
;
166 StructWithBitfield bitfieldvar
= { (uintptr_t)&bitfieldvar
}; // expected-error {{initializer element is not a compile-time constant}}