| Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s | 
| Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 2 |  | 
|  | 3 | struct foo { int a, b; }; | 
|  | 4 |  | 
| Nuno Lopes | 7bfa180 | 2008-07-07 16:46:50 +0000 | [diff] [blame] | 5 | static struct foo t = (struct foo){0,0}; | 
| Steve Naroff | 66a2604 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 6 | static struct foo t2 = {0,0}; | 
| Chris Lattner | 28b4294 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 7 | static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}} | 
| Steve Naroff | 66a2604 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 8 | static int *p = (int []){2,4}; | 
| Eli Friedman | 0b4af8f | 2009-05-16 11:45:48 +0000 | [diff] [blame] | 9 | static int x = (int){1}; | 
| Steve Naroff | 66a2604 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 10 |  | 
| Chris Lattner | 28b4294 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 11 | 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^] | 12 | 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] | 13 |  | 
| Nuno Lopes | 7bfa180 | 2008-07-07 16:46:50 +0000 | [diff] [blame] | 14 | typedef struct { } cache_t; // -expected-warning{{use of empty struct extension}} | 
|  | 15 | static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}} | 
|  | 16 |  | 
| Steve Naroff | d32419d | 2008-01-14 18:19:28 +0000 | [diff] [blame] | 17 | typedef struct Test {int a;int b;} Test; | 
|  | 18 | static Test* ll = &(Test) {0,0}; | 
|  | 19 |  | 
| Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 20 | extern void fooFunc(struct foo *pfoo); | 
|  | 21 |  | 
|  | 22 | int main(int argc, char **argv) { | 
| Steve Naroff | 08ddb8c | 2008-01-09 20:58:06 +0000 | [diff] [blame] | 23 | int *l = (int []){x, *p, *p2}; | 
| Steve Naroff | 2644aaf | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 24 | fooFunc(&(struct foo){ 1, 2 }); | 
|  | 25 | } | 
|  | 26 |  | 
| Douglas Gregor | dd430f7 | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 27 | struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}} | 
| Eli Friedman | 37a186d | 2008-05-20 05:22:08 +0000 | [diff] [blame] | 28 | struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}} | 
|  | 29 | void IncompleteFunc(unsigned x) { | 
|  | 30 | 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] | 31 | (void){1,2,3}; // -expected-error {{variable has incomplete type}} | 
| Chris Lattner | 1e5665e | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 32 | (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}} | 
| Eli Friedman | 37a186d | 2008-05-20 05:22:08 +0000 | [diff] [blame] | 33 | } | 
| John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 34 |  | 
|  | 35 | // PR6080 | 
|  | 36 | int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1]; |