init.c revision d863517ab7e936cbc3244a0fc431c8b672f5ece4
1// RUN: clang %s -verify -fsyntax-only
2
3typedef void (* fp)(void);
4void foo(void);
5
6// PR clang/3377
7fp a[(short int)1] = { foo };
8
9int myArray[5] = {1, 2, 3, 4, 5};
10int *myPointer2 = myArray;
11int *myPointer = &(myArray[2]);
12
13
14extern int x;
15void *g = &x;
16int *h = &x;
17
18int test() {
19int a[10];
20int b[10] = a; // expected-error {{initialization with '{...}' expected}}
21int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}}
22}
23
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
36// PR2348
37static struct { int z; } s[2];
38int *t = &(*s).z;
39
40// PR2349
41short *a2(void)
42{
43  short int b;
44  static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
45
46  return bp;
47}
48
49int pbool(void) {
50  typedef const _Bool cbool;
51  _Bool pbool1 = (void *) 0;
52  cbool pbool2 = &pbool;
53  return pbool2;
54}
55
56
57// rdar://5870981
58union { float f; unsigned u; } u = { 1.0f };
59
60// rdar://6156694
61int f3(int x) { return x; }
62typedef void (*vfunc)(void);
63void *bar = (vfunc) f3;
64
65// PR2747
66struct sym_reg {
67        char nc_gpreg;
68};
69int sym_fw1a_scr[] = {
70           ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
71           8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
72};
73
74// PR3001
75struct s1 s2 = {
76    .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
77                            // expected-note{{forward declaration of 'struct s3'}}
78    .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
79}
80
81// PR3382
82char t[] = ("Hello");
83
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 = {} };
99
100int bbb[10];
101
102struct foo2 {
103   unsigned a;
104};
105
106struct foo2 bar2[] = {
107   { (int)bbb }
108};
109