| Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s | 
| NAKAMURA Takumi | fcd16e3 | 2012-09-12 10:45:40 +0000 | [diff] [blame^] | 2 | // REQUIRES: LP64 | 
| Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 3 |  | 
|  | 4 | struct foo { int a, b; }; | 
|  | 5 |  | 
| Nuno Lopes | 7bfa180 | 2008-07-07 16:46:50 +0000 | [diff] [blame] | 6 | static struct foo t = (struct foo){0,0}; | 
| Abramo Bagnara | b59a5b6 | 2010-09-27 07:13:32 +0000 | [diff] [blame] | 7 | static struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0}); | 
|  | 8 | static struct foo t2 = {0,0}; | 
| Chris Lattner | 28b4294 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 9 | static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}} | 
| Abramo Bagnara | b59a5b6 | 2010-09-27 07:13:32 +0000 | [diff] [blame] | 10 | static int *p = (int []){2,4}; | 
| Eli Friedman | 0b4af8f | 2009-05-16 11:45:48 +0000 | [diff] [blame] | 11 | static int x = (int){1}; | 
| Steve Naroff | 66a2604 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 12 |  | 
| Chris Lattner | 28b4294 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 13 | static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}} | 
| Douglas Gregor | b10646d | 2010-04-09 17:53:29 +0000 | [diff] [blame] | 14 | static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}} | 
| Steve Naroff | 08ddb8c | 2008-01-09 20:58:06 +0000 | [diff] [blame] | 15 |  | 
| Richard Smith | e434590 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 16 | typedef struct { } cache_t; // -expected-warning{{empty struct is a GNU extension}} | 
| Nuno Lopes | 7bfa180 | 2008-07-07 16:46:50 +0000 | [diff] [blame] | 17 | static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}} | 
|  | 18 |  | 
| Steve Naroff | d32419d | 2008-01-14 18:19:28 +0000 | [diff] [blame] | 19 | typedef struct Test {int a;int b;} Test; | 
|  | 20 | static Test* ll = &(Test) {0,0}; | 
|  | 21 |  | 
| Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 22 | extern void fooFunc(struct foo *pfoo); | 
|  | 23 |  | 
|  | 24 | int main(int argc, char **argv) { | 
| Steve Naroff | 08ddb8c | 2008-01-09 20:58:06 +0000 | [diff] [blame] | 25 | int *l = (int []){x, *p, *p2}; | 
| Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 26 | fooFunc(&(struct foo){ 1, 2 }); | 
|  | 27 | } | 
|  | 28 |  | 
| Douglas Gregor | dd430f7 | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 29 | struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}} | 
| Eli Friedman | 37a186d | 2008-05-20 05:22:08 +0000 | [diff] [blame] | 30 | struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}} | 
|  | 31 | void IncompleteFunc(unsigned x) { | 
|  | 32 | struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}} | 
| Eli Friedman | d0e48ea | 2008-05-20 05:25:56 +0000 | [diff] [blame] | 33 | (void){1,2,3}; // -expected-error {{variable has incomplete type}} | 
| Chris Lattner | 1e5665e | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 34 | (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}} | 
| Eli Friedman | 37a186d | 2008-05-20 05:22:08 +0000 | [diff] [blame] | 35 | } | 
| John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 36 |  | 
|  | 37 | // PR6080 | 
|  | 38 | int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1]; |