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