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