blob: 80dd370962a86095488cd6859c4f8698a7d15e4b [file] [log] [blame]
Steve Naroff92590f92008-01-09 20:58:06 +00001// RUN: clang -fsyntax-only -verify -pedantic %s
Steve Naroffc7c66532007-12-05 04:00:10 +00002
3struct foo { int a, b; };
4
Steve Narofff91f9722008-01-09 00:05:37 +00005static struct foo t = (struct foo){0,0}; // -expected-error {{initializer element is not constant}}
6static struct foo t2 = {0,0};
7static struct foo t3 = t2; // -expected-error {{initializer element is not constant}}
8static int *p = (int []){2,4};
9static int x = (int){1}; // -expected-error {{initializer element is not constant}} -expected-warning{{braces around scalar initializer}}
10
Steve Naroff92590f92008-01-09 20:58:06 +000011static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not constant}}
Chris Lattnera6dcce32008-02-11 00:02:17 +000012static int *p3 = (int []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char [2]', expected 'int'}}
Steve Naroff92590f92008-01-09 20:58:06 +000013
Steve Naroffbe37fc02008-01-14 18:19:28 +000014typedef struct Test {int a;int b;} Test;
15static Test* ll = &(Test) {0,0};
16
Steve Naroffc7c66532007-12-05 04:00:10 +000017extern void fooFunc(struct foo *pfoo);
18
19int main(int argc, char **argv) {
Steve Naroff92590f92008-01-09 20:58:06 +000020 int *l = (int []){x, *p, *p2};
Steve Naroffc7c66532007-12-05 04:00:10 +000021 fooFunc(&(struct foo){ 1, 2 });
22}
23
Eli Friedman8c2173d2008-05-20 05:22:08 +000024struct Incomplete;
25struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
26void IncompleteFunc(unsigned x) {
27 struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
Eli Friedmanb9ea6bc2008-05-20 05:25:56 +000028 (void){1,2,3}; // -expected-error {{variable has incomplete type}}
Eli Friedman8c2173d2008-05-20 05:22:08 +000029}