Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 1 | // RUN: clang %s -verify -fsyntax-only |
| 2 | |
| 3 | typedef void (* fp)(void); |
| 4 | void foo(void); |
Douglas Gregor | f6c717c | 2009-01-23 16:54:12 +0000 | [diff] [blame] | 5 | |
| 6 | // PR clang/3377 |
| 7 | fp a[(short int)1] = { foo }; |
Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 8 | |
Chris Lattner | 4cc6271 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 9 | int myArray[5] = {1, 2, 3, 4, 5}; |
| 10 | int *myPointer2 = myArray; |
| 11 | int *myPointer = &(myArray[2]); |
| 12 | |
Chris Lattner | d411e04 | 2007-12-02 07:47:49 +0000 | [diff] [blame] | 13 | |
| 14 | extern int x; |
| 15 | void *g = &x; |
| 16 | int *h = &x; |
| 17 | |
Eli Friedman | a312ce2 | 2008-02-08 00:48:24 +0000 | [diff] [blame] | 18 | int test() { |
| 19 | int a[10]; |
Sebastian Redl | 9f4d863 | 2008-11-22 22:39:41 +0000 | [diff] [blame] | 20 | int b[10] = a; // expected-error {{initialization with '{...}' expected}} |
Chris Lattner | 1f6f54b | 2008-11-11 06:13:16 +0000 | [diff] [blame] | 21 | int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}} |
Eli Friedman | a312ce2 | 2008-02-08 00:48:24 +0000 | [diff] [blame] | 22 | } |
Chris Lattner | be34ac6 | 2008-05-04 01:13:36 +0000 | [diff] [blame] | 23 | |
| 24 | |
| 25 | // PR2050 |
| 26 | struct cdiff_cmd { |
| 27 | const char *name; |
| 28 | unsigned short argc; |
| 29 | int (*handler)(); |
| 30 | }; |
| 31 | int cdiff_cmd_open(); |
| 32 | struct cdiff_cmd commands[] = { |
| 33 | {"OPEN", 1, &cdiff_cmd_open } |
| 34 | }; |
| 35 | |
Eli Friedman | 97c0a39 | 2008-05-21 03:39:11 +0000 | [diff] [blame] | 36 | // PR2348 |
| 37 | static struct { int z; } s[2]; |
| 38 | int *t = &(*s).z; |
| 39 | |
| 40 | // PR2349 |
| 41 | short *a2(void) |
| 42 | { |
| 43 | short int b; |
Chris Lattner | d880363 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 44 | static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}} |
Eli Friedman | 97c0a39 | 2008-05-21 03:39:11 +0000 | [diff] [blame] | 45 | |
| 46 | return bp; |
| 47 | } |
Eli Friedman | f8f873d | 2008-05-30 18:07:22 +0000 | [diff] [blame] | 48 | |
| 49 | int pbool(void) { |
| 50 | typedef const _Bool cbool; |
| 51 | _Bool pbool1 = (void *) 0; |
| 52 | cbool pbool2 = &pbool; |
| 53 | return pbool2; |
| 54 | } |
| 55 | |
Chris Lattner | d5bac57 | 2008-08-19 00:58:40 +0000 | [diff] [blame] | 56 | |
| 57 | // rdar://5870981 |
| 58 | union { float f; unsigned u; } u = { 1.0f }; |
| 59 | |
Daniel Dunbar | 1e465df | 2008-08-25 20:08:27 +0000 | [diff] [blame] | 60 | // rdar://6156694 |
| 61 | int f3(int x) { return x; } |
| 62 | typedef void (*vfunc)(void); |
| 63 | void *bar = (vfunc) f3; |
Eli Friedman | b529d83 | 2008-09-02 09:37:00 +0000 | [diff] [blame] | 64 | |
| 65 | // PR2747 |
| 66 | struct sym_reg { |
| 67 | char nc_gpreg; |
| 68 | }; |
| 69 | int sym_fw1a_scr[] = { |
Nuno Lopes | 67c8601 | 2008-09-02 10:10:14 +0000 | [diff] [blame] | 70 | ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0, |
| 71 | 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg)) |
Eli Friedman | b529d83 | 2008-09-02 09:37:00 +0000 | [diff] [blame] | 72 | }; |
Chris Lattner | e2f5619 | 2008-11-03 09:28:22 +0000 | [diff] [blame] | 73 | |
| 74 | // PR3001 |
| 75 | struct s1 s2 = { |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 76 | .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \ |
| 77 | // expected-note{{forward declaration of 'struct s3'}} |
Chris Lattner | e2f5619 | 2008-11-03 09:28:22 +0000 | [diff] [blame] | 78 | .b = bogus // expected-error {{use of undeclared identifier 'bogus'}} |
| 79 | } |
| 80 | |
Anders Carlsson | 91b9f20 | 2009-01-24 17:47:50 +0000 | [diff] [blame] | 81 | // PR3382 |
| 82 | char t[] = ("Hello"); |
Douglas Gregor | d079b2d | 2009-01-30 17:42:28 +0000 | [diff] [blame] | 83 | |
| 84 | // <rdar://problem/6094855> |
| 85 | typedef struct { } empty; |
| 86 | |
| 87 | typedef struct { |
| 88 | empty e; |
| 89 | int i2; |
| 90 | } st; |
| 91 | |
| 92 | st st1 = { .i2 = 1 }; |
| 93 | |
| 94 | // <rdar://problem/6096826> |
| 95 | struct { |
| 96 | int a; |
| 97 | int z[2]; |
| 98 | } y = { .z = {} }; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame^] | 99 | |
| 100 | int bbb[10]; |
| 101 | |
| 102 | struct foo2 { |
| 103 | unsigned a; |
| 104 | }; |
| 105 | |
| 106 | struct foo2 bar2[] = { |
| 107 | { (int)bbb } |
| 108 | }; |