blob: 41307625999e6534997964002f0e2c6a0f6edb08 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -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};
Abramo Bagnara5cadfab2010-09-27 07:13:32 +00006static struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0});
7static struct foo t2 = {0,0};
Chris Lattnerd8803632008-08-10 01:58:45 +00008static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}}
Abramo Bagnara5cadfab2010-09-27 07:13:32 +00009static int *p = (int []){2,4};
Eli Friedman759f2522009-05-16 11:45:48 +000010static int x = (int){1};
Steve Naroffb8f13a82008-01-09 00:05:37 +000011
Chris Lattnerd8803632008-08-10 01:58:45 +000012static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}}
Douglas Gregor08a41902010-04-09 17:53:29 +000013static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}}
Steve Naroff58d18212008-01-09 20:58:06 +000014
Douglas Gregor03332962010-07-29 14:29:34 +000015typedef struct { } cache_t; // -expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}}
Nuno Lopes9a979c32008-07-07 16:46:50 +000016static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}}
17
Steve Naroffe9b12192008-01-14 18:19:28 +000018typedef struct Test {int a;int b;} Test;
19static Test* ll = &(Test) {0,0};
20
Steve Naroffe6386392007-12-05 04:00:10 +000021extern void fooFunc(struct foo *pfoo);
22
23int main(int argc, char **argv) {
Steve Naroff58d18212008-01-09 20:58:06 +000024 int *l = (int []){x, *p, *p2};
Steve Naroffe6386392007-12-05 04:00:10 +000025 fooFunc(&(struct foo){ 1, 2 });
26}
27
Douglas Gregor4ec339f2009-01-19 19:26:10 +000028struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}}
Eli Friedman6223c222008-05-20 05:22:08 +000029struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
30void IncompleteFunc(unsigned x) {
31 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 +000032 (void){1,2,3}; // -expected-error {{variable has incomplete type}}
Chris Lattnerd1625842008-11-24 06:25:27 +000033 (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}}
Eli Friedman6223c222008-05-20 05:22:08 +000034}
John McCall1d7d8d62010-01-19 22:33:45 +000035
36// PR6080
37int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1];