blob: e77cbfcdcfe89bc45d18f33696f40495ecb907b1 [file] [log] [blame]
Chris Lattner4ef8dd62007-11-01 02:45:17 +00001// RUN: clang %s -verify -fsyntax-only
2
Sebastian Redl392cf912009-02-07 00:23:52 +00003#include <stdint.h>
4
Chris Lattner4ef8dd62007-11-01 02:45:17 +00005typedef void (* fp)(void);
6void foo(void);
Douglas Gregorf6c717c2009-01-23 16:54:12 +00007
8// PR clang/3377
9fp a[(short int)1] = { foo };
Chris Lattner4ef8dd62007-11-01 02:45:17 +000010
Chris Lattner4cc62712007-11-27 21:35:27 +000011int myArray[5] = {1, 2, 3, 4, 5};
12int *myPointer2 = myArray;
13int *myPointer = &(myArray[2]);
14
Chris Lattnerd411e042007-12-02 07:47:49 +000015
16extern int x;
17void *g = &x;
18int *h = &x;
19
Eli Friedmana312ce22008-02-08 00:48:24 +000020int test() {
21int a[10];
Sebastian Redl9f4d8632008-11-22 22:39:41 +000022int b[10] = a; // expected-error {{initialization with '{...}' expected}}
Chris Lattner1f6f54b2008-11-11 06:13:16 +000023int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}}
Eli Friedmana312ce22008-02-08 00:48:24 +000024}
Chris Lattnerbe34ac62008-05-04 01:13:36 +000025
26
27// PR2050
28struct cdiff_cmd {
29 const char *name;
30 unsigned short argc;
31 int (*handler)();
32};
33int cdiff_cmd_open();
34struct cdiff_cmd commands[] = {
35 {"OPEN", 1, &cdiff_cmd_open }
36};
37
Eli Friedman97c0a392008-05-21 03:39:11 +000038// PR2348
39static struct { int z; } s[2];
40int *t = &(*s).z;
41
42// PR2349
43short *a2(void)
44{
45 short int b;
Chris Lattnerd8803632008-08-10 01:58:45 +000046 static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}}
Eli Friedman97c0a392008-05-21 03:39:11 +000047
48 return bp;
49}
Eli Friedmanf8f873d2008-05-30 18:07:22 +000050
51int pbool(void) {
52 typedef const _Bool cbool;
53 _Bool pbool1 = (void *) 0;
54 cbool pbool2 = &pbool;
55 return pbool2;
56}
57
Chris Lattnerd5bac572008-08-19 00:58:40 +000058
59// rdar://5870981
60union { float f; unsigned u; } u = { 1.0f };
61
Daniel Dunbar1e465df2008-08-25 20:08:27 +000062// rdar://6156694
63int f3(int x) { return x; }
64typedef void (*vfunc)(void);
65void *bar = (vfunc) f3;
Eli Friedmanb529d832008-09-02 09:37:00 +000066
67// PR2747
68struct sym_reg {
69 char nc_gpreg;
70};
71int sym_fw1a_scr[] = {
Nuno Lopes67c86012008-09-02 10:10:14 +000072 ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
73 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
Eli Friedmanb529d832008-09-02 09:37:00 +000074};
Chris Lattnere2f56192008-11-03 09:28:22 +000075
76// PR3001
77struct s1 s2 = {
Douglas Gregor4ec339f2009-01-19 19:26:10 +000078 .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
79 // expected-note{{forward declaration of 'struct s3'}}
Chris Lattnere2f56192008-11-03 09:28:22 +000080 .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
81}
82
Anders Carlsson91b9f202009-01-24 17:47:50 +000083// PR3382
84char t[] = ("Hello");
Douglas Gregord079b2d2009-01-30 17:42:28 +000085
86// <rdar://problem/6094855>
87typedef struct { } empty;
88
89typedef struct {
90 empty e;
91 int i2;
92} st;
93
94st st1 = { .i2 = 1 };
95
96// <rdar://problem/6096826>
97struct {
98 int a;
99 int z[2];
100} y = { .z = {} };
Douglas Gregord8635172009-02-02 21:35:47 +0000101
102int bbb[10];
103
104struct foo2 {
Eli Friedmanc91b7d92009-02-22 07:40:57 +0000105 uintptr_t a;
Douglas Gregord8635172009-02-02 21:35:47 +0000106};
107
108struct foo2 bar2[] = {
Sebastian Redl392cf912009-02-07 00:23:52 +0000109 { (intptr_t)bbb }
Douglas Gregord8635172009-02-02 21:35:47 +0000110};
Douglas Gregor7c53ca62009-02-18 22:23:55 +0000111
112struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}}