1// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s 2 3struct foo { int a, b; }; 4 5static struct foo t = (struct foo){0,0}; 6static struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0}); 7static struct foo t2 = {0,0}; 8static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}} 9static int *p = (int []){2,4}; 10static int x = (int){1}; 11 12static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}} 13static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}} 14 15typedef struct { } cache_t; // -expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}} 16static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}} 17 18typedef struct Test {int a;int b;} Test; 19static Test* ll = &(Test) {0,0}; 20 21extern void fooFunc(struct foo *pfoo); 22 23int main(int argc, char **argv) { 24 int *l = (int []){x, *p, *p2}; 25 fooFunc(&(struct foo){ 1, 2 }); 26} 27 28struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}} 29struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}} 30void IncompleteFunc(unsigned x) { 31 struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}} 32 (void){1,2,3}; // -expected-error {{variable has incomplete type}} 33 (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}} 34} 35 36// PR6080 37int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1]; 38