blob: bac7b0e6024631467b68504b784a7ede3cd93f10 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +00002// REQUIRES: LP64
Steve Naroff2644aaf2007-12-05 04:00:10 +00003
4struct foo { int a, b; };
5
Nuno Lopes7bfa1802008-07-07 16:46:50 +00006static struct foo t = (struct foo){0,0};
Abramo Bagnarab59a5b62010-09-27 07:13:32 +00007static struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0});
8static struct foo t2 = {0,0};
Chris Lattner28b42942008-08-10 01:58:45 +00009static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}}
Abramo Bagnarab59a5b62010-09-27 07:13:32 +000010static int *p = (int []){2,4};
Eli Friedman0b4af8f2009-05-16 11:45:48 +000011static int x = (int){1};
Steve Naroff66a26042008-01-09 00:05:37 +000012
Chris Lattner28b42942008-08-10 01:58:45 +000013static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}}
Douglas Gregorb10646d2010-04-09 17:53:29 +000014static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}}
Steve Naroff08ddb8c2008-01-09 20:58:06 +000015
Richard Smithe4345902011-12-29 21:57:33 +000016typedef struct { } cache_t; // -expected-warning{{empty struct is a GNU extension}}
Nuno Lopes7bfa1802008-07-07 16:46:50 +000017static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}}
18
Steve Naroffd32419d2008-01-14 18:19:28 +000019typedef struct Test {int a;int b;} Test;
20static Test* ll = &(Test) {0,0};
21
Steve Naroff2644aaf2007-12-05 04:00:10 +000022extern void fooFunc(struct foo *pfoo);
23
24int main(int argc, char **argv) {
Steve Naroff08ddb8c2008-01-09 20:58:06 +000025 int *l = (int []){x, *p, *p2};
Steve Naroff2644aaf2007-12-05 04:00:10 +000026 fooFunc(&(struct foo){ 1, 2 });
27}
28
Douglas Gregordd430f72009-01-19 19:26:10 +000029struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}}
Eli Friedman37a186d2008-05-20 05:22:08 +000030struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
31void IncompleteFunc(unsigned x) {
32 struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
Eli Friedmand0e48ea2008-05-20 05:25:56 +000033 (void){1,2,3}; // -expected-error {{variable has incomplete type}}
Chris Lattner1e5665e2008-11-24 06:25:27 +000034 (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}}
Eli Friedman37a186d2008-05-20 05:22:08 +000035}
John McCall5d7aa7f2010-01-19 22:33:45 +000036
37// PR6080
38int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1];