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