Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify -pedantic %s |
Steve Naroff | e638639 | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 2 | |
| 3 | struct foo { int a, b; }; |
| 4 | |
Nuno Lopes | 9a979c3 | 2008-07-07 16:46:50 +0000 | [diff] [blame] | 5 | static struct foo t = (struct foo){0,0}; |
Steve Naroff | b8f13a8 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 6 | static struct foo t2 = {0,0}; |
Chris Lattner | d880363 | 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 | b8f13a8 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 8 | static int *p = (int []){2,4}; |
Nuno Lopes | 9a979c3 | 2008-07-07 16:46:50 +0000 | [diff] [blame] | 9 | static int x = (int){1}; // -expected-warning{{braces around scalar initializer}} |
Steve Naroff | b8f13a8 | 2008-01-09 00:05:37 +0000 | [diff] [blame] | 10 | |
Chris Lattner | d880363 | 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}} |
Sebastian Redl | 1367ede | 2008-11-12 21:19:11 +0000 | [diff] [blame] | 12 | static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'char [2]', expected 'long'}} |
Steve Naroff | 58d1821 | 2008-01-09 20:58:06 +0000 | [diff] [blame] | 13 | |
Nuno Lopes | 9a979c3 | 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 | e9b1219 | 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 | e638639 | 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 | 58d1821 | 2008-01-09 20:58:06 +0000 | [diff] [blame] | 23 | int *l = (int []){x, *p, *p2}; |
Steve Naroff | e638639 | 2007-12-05 04:00:10 +0000 | [diff] [blame] | 24 | fooFunc(&(struct foo){ 1, 2 }); |
| 25 | } |
| 26 | |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 27 | struct Incomplete; // expected-note{{forward declaration of 'struct Incomplete'}} |
Eli Friedman | 6223c22 | 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 | d8dc210 | 2008-05-20 05:25:56 +0000 | [diff] [blame] | 31 | (void){1,2,3}; // -expected-error {{variable has incomplete type}} |
Chris Lattner | d162584 | 2008-11-24 06:25:27 +0000 | [diff] [blame] | 32 | (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}} |
Eli Friedman | 6223c22 | 2008-05-20 05:22:08 +0000 | [diff] [blame] | 33 | } |