blob: 3c8f3fe134903cb273a9fbd238ae5fc5adc4ab1d [file] [log] [blame]
Chris Lattner4ef8dd62007-11-01 02:45:17 +00001// RUN: clang %s -verify -fsyntax-only
2
3typedef void (* fp)(void);
4void foo(void);
Douglas Gregorf6c717c2009-01-23 16:54:12 +00005
6// PR clang/3377
7fp a[(short int)1] = { foo };
Chris Lattner4ef8dd62007-11-01 02:45:17 +00008
Chris Lattner4cc62712007-11-27 21:35:27 +00009int myArray[5] = {1, 2, 3, 4, 5};
10int *myPointer2 = myArray;
11int *myPointer = &(myArray[2]);
12
Chris Lattnerd411e042007-12-02 07:47:49 +000013
14extern int x;
15void *g = &x;
16int *h = &x;
17
Eli Friedmana312ce22008-02-08 00:48:24 +000018int test() {
19int a[10];
Sebastian Redl9f4d8632008-11-22 22:39:41 +000020int b[10] = a; // expected-error {{initialization with '{...}' expected}}
Chris Lattner1f6f54b2008-11-11 06:13:16 +000021int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}}
Eli Friedmana312ce22008-02-08 00:48:24 +000022}
Chris Lattnerbe34ac62008-05-04 01:13:36 +000023
24
25// PR2050
26struct cdiff_cmd {
27 const char *name;
28 unsigned short argc;
29 int (*handler)();
30};
31int cdiff_cmd_open();
32struct cdiff_cmd commands[] = {
33 {"OPEN", 1, &cdiff_cmd_open }
34};
35
Eli Friedman97c0a392008-05-21 03:39:11 +000036// PR2348
37static struct { int z; } s[2];
38int *t = &(*s).z;
39
40// PR2349
41short *a2(void)
42{
43 short int b;
Chris Lattnerd8803632008-08-10 01:58:45 +000044 static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
Eli Friedman97c0a392008-05-21 03:39:11 +000045
46 return bp;
47}
Eli Friedmanf8f873d2008-05-30 18:07:22 +000048
49int pbool(void) {
50 typedef const _Bool cbool;
51 _Bool pbool1 = (void *) 0;
52 cbool pbool2 = &pbool;
53 return pbool2;
54}
55
Chris Lattnerd5bac572008-08-19 00:58:40 +000056
57// rdar://5870981
58union { float f; unsigned u; } u = { 1.0f };
59
Daniel Dunbar1e465df2008-08-25 20:08:27 +000060// rdar://6156694
61int f3(int x) { return x; }
62typedef void (*vfunc)(void);
63void *bar = (vfunc) f3;
Eli Friedmanb529d832008-09-02 09:37:00 +000064
65// PR2747
66struct sym_reg {
67 char nc_gpreg;
68};
69int sym_fw1a_scr[] = {
Nuno Lopes67c86012008-09-02 10:10:14 +000070 ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
71 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
Eli Friedmanb529d832008-09-02 09:37:00 +000072};
Chris Lattnere2f56192008-11-03 09:28:22 +000073
74// PR3001
75struct s1 s2 = {
Douglas Gregor4ec339f2009-01-19 19:26:10 +000076 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
77 // expected-note{{forward declaration of 'struct s3'}}
Chris Lattnere2f56192008-11-03 09:28:22 +000078 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
79}
80
Anders Carlsson91b9f202009-01-24 17:47:50 +000081// PR3382
82char t[] = ("Hello");
Douglas Gregord079b2d2009-01-30 17:42:28 +000083
84// <rdar://problem/6094855>
85typedef struct { } empty;
86
87typedef struct {
88 empty e;
89 int i2;
90} st;
91
92st st1 = { .i2 = 1 };
93
94// <rdar://problem/6096826>
95struct {
96 int a;
97 int z[2];
98} y = { .z = {} };
Douglas Gregord8635172009-02-02 21:35:47 +000099
100int bbb[10];
101
102struct foo2 {
103 unsigned a;
104};
105
106struct foo2 bar2[] = {
107 { (int)bbb }
108};