compound-literal.c revision d8dc2100487640d8f5ce53201fdcfac7b5ca32b2
1a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod// RUN: clang -fsyntax-only -verify -pedantic %s 22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod 32409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbodstruct foo { int a, b; }; 42409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod 59f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbodstatic struct foo t = (struct foo){0,0}; // -expected-error {{initializer element is not constant}} 68f0d7e0c3fd4b05c43ac449be4f374dc2dc56127Behdad Esfahbodstatic struct foo t2 = {0,0}; 79f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbodstatic struct foo t3 = t2; // -expected-error {{initializer element is not constant}} 8a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstatic int *p = (int []){2,4}; 9a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstatic int x = (int){1}; // -expected-error {{initializer element is not constant}} -expected-warning{{braces around scalar initializer}} 10a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod 11a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstatic int *p2 = (int []){2,x}; // -expected-error {{initializer element is not constant}} 12a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstatic int *p3 = (int []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char [2]', expected 'int'}} 13a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod 14a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodtypedef struct Test {int a;int b;} Test; 15a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstatic Test* ll = &(Test) {0,0}; 16a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod 17a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodextern void fooFunc(struct foo *pfoo); 18a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod 19a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodint main(int argc, char **argv) { 20a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod int *l = (int []){x, *p, *p2}; 21a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod fooFunc(&(struct foo){ 1, 2 }); 22a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod} 23a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod 24a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstruct Incomplete; 25a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodstruct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}} 26a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbodvoid IncompleteFunc(unsigned x) { 27c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}} 289f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod (void){1,2,3}; // -expected-error {{variable has incomplete type}} 299f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod} 3022da7fd94d6318c52df69d70470a85464ffc533dBehdad Esfahbod