blob: f25d54fc90fd1201c216e385b670407cc5caac94 [file] [log] [blame]
Steve Naroff58d18212008-01-09 20:58:06 +00001// RUN: clang -fsyntax-only -verify -pedantic %s
Steve Naroffe6386392007-12-05 04:00:10 +00002
3struct foo { int a, b; };
4
Nuno Lopes9a979c32008-07-07 16:46:50 +00005static struct foo t = (struct foo){0,0};
Steve Naroffb8f13a82008-01-09 00:05:37 +00006static struct foo t2 = {0,0};
7static struct foo t3 = t2; // -expected-error {{initializer element is not constant}}
8static int *p = (int []){2,4};
Nuno Lopes9a979c32008-07-07 16:46:50 +00009static int x = (int){1}; // -expected-warning{{braces around scalar initializer}}
Steve Naroffb8f13a82008-01-09 00:05:37 +000010
Steve Naroff58d18212008-01-09 20:58:06 +000011static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not constant}}
Chris Lattnera7ad98f2008-02-11 00:02:17 +000012static int *p3 = (int []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char [2]', expected 'int'}}
Steve Naroff58d18212008-01-09 20:58:06 +000013
Nuno Lopes9a979c32008-07-07 16:46:50 +000014typedef 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
Steve Naroffe9b12192008-01-14 18:19:28 +000017typedef struct Test {int a;int b;} Test;
18static Test* ll = &(Test) {0,0};
19
Steve Naroffe6386392007-12-05 04:00:10 +000020extern void fooFunc(struct foo *pfoo);
21
22int main(int argc, char **argv) {
Steve Naroff58d18212008-01-09 20:58:06 +000023 int *l = (int []){x, *p, *p2};
Steve Naroffe6386392007-12-05 04:00:10 +000024 fooFunc(&(struct foo){ 1, 2 });
25}
26
Eli Friedman6223c222008-05-20 05:22:08 +000027struct 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}}
Eli Friedmand8dc2102008-05-20 05:25:56 +000031 (void){1,2,3}; // -expected-error {{variable has incomplete type}}
Eli Friedman6223c222008-05-20 05:22:08 +000032}