1*67e74705SXin Li // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
2*67e74705SXin Li
3*67e74705SXin Li extern int a1[];
4*67e74705SXin Li
5*67e74705SXin Li void f0();
6*67e74705SXin Li void f1(int [*]);
7*67e74705SXin Li void f2(int [const *]);
8*67e74705SXin Li void f3(int [volatile const*]);
9*67e74705SXin Li int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */
10*67e74705SXin Li int f5(int [static]); /* expected-error {{'static' may not be used without an array size}} */
11*67e74705SXin Li
12*67e74705SXin Li char ((((*X))));
13*67e74705SXin Li
14*67e74705SXin Li void (*signal(int, void (*)(int)))(int);
15*67e74705SXin Li
16*67e74705SXin Li int aaaa, ***C, * const D, B(int);
17*67e74705SXin Li
18*67e74705SXin Li int *A;
19*67e74705SXin Li
20*67e74705SXin Li struct str;
21*67e74705SXin Li
test2(int * P,int A)22*67e74705SXin Li void test2(int *P, int A) {
23*67e74705SXin Li struct str;
24*67e74705SXin Li
25*67e74705SXin Li // Hard case for array decl, not Array[*].
26*67e74705SXin Li int Array[*(int*)P+A];
27*67e74705SXin Li }
28*67e74705SXin Li
29*67e74705SXin Li typedef int atype;
test3(x,atype)30*67e74705SXin Li void test3(x,
31*67e74705SXin Li atype /* expected-error {{unexpected type name 'atype': expected identifier}} */
32*67e74705SXin Li ) int x, atype; {}
33*67e74705SXin Li
test4(x,x)34*67e74705SXin Li void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */
35*67e74705SXin Li
36*67e74705SXin Li
37*67e74705SXin Li // PR3031
38*67e74705SXin Li int (test5), ; // expected-error {{expected identifier or '('}}
39*67e74705SXin Li
40*67e74705SXin Li
41*67e74705SXin Li
42*67e74705SXin Li // PR3963 & rdar://6759604 - test error recovery for mistyped "typenames".
43*67e74705SXin Li
44*67e74705SXin Li foo_t *d; // expected-error {{unknown type name 'foo_t'}}
45*67e74705SXin Li foo_t a; // expected-error {{unknown type name 'foo_t'}}
test6()46*67e74705SXin Li int test6() { return a; } // a should be declared.
47*67e74705SXin Li
48*67e74705SXin Li // Use of tagged type without tag. rdar://6783347
49*67e74705SXin Li struct xyz { int y; };
50*67e74705SXin Li enum myenum { ASDFAS };
51*67e74705SXin Li xyz b; // expected-error {{must use 'struct' tag to refer to type 'xyz'}}
52*67e74705SXin Li myenum c; // expected-error {{must use 'enum' tag to refer to type 'myenum'}}
53*67e74705SXin Li
test7()54*67e74705SXin Li float *test7() {
55*67e74705SXin Li // We should recover 'b' by parsing it with a valid type of "struct xyz", which
56*67e74705SXin Li // allows us to diagnose other bad things done with y, such as this.
57*67e74705SXin Li return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}}
58*67e74705SXin Li }
59*67e74705SXin Li
test8()60*67e74705SXin Li struct xyz test8() { return a; } // a should be be marked invalid, no diag.
61*67e74705SXin Li
62*67e74705SXin Li
63*67e74705SXin Li // Verify that implicit int still works.
64*67e74705SXin Li static f; // expected-warning {{type specifier missing, defaults to 'int'}}
65*67e74705SXin Li static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}}
66*67e74705SXin Li static h // expected-warning {{type specifier missing, defaults to 'int'}}
67*67e74705SXin Li __asm__("foo");
68*67e74705SXin Li
69*67e74705SXin Li
70*67e74705SXin Li struct test9 {
71*67e74705SXin Li int x // expected-error {{expected ';' at end of declaration list}}
72*67e74705SXin Li int y;
73*67e74705SXin Li int z // expected-warning {{expected ';' at end of declaration list}}
74*67e74705SXin Li };
75*67e74705SXin Li
76*67e74705SXin Li // PR6208
77*67e74705SXin Li struct test10 { int a; } static test10x;
78*67e74705SXin Li struct test11 { int a; } const test11x;
79*67e74705SXin Li
80*67e74705SXin Li // PR6216
test12()81*67e74705SXin Li void test12() {
82*67e74705SXin Li (void)__builtin_offsetof(struct { char c; int i; }, i);
83*67e74705SXin Li }
84*67e74705SXin Li
85*67e74705SXin Li // rdar://7608537
86*67e74705SXin Li struct test13 { int a; } (test13x);
87*67e74705SXin Li
88*67e74705SXin Li // <rdar://problem/8044088>
89*67e74705SXin Li struct X<foo::int> { }; // expected-error{{expected identifier or '('}}
90*67e74705SXin Li
91*67e74705SXin Li
92*67e74705SXin Li // PR7617 - error recovery on missing ;.
93*67e74705SXin Li
94*67e74705SXin Li void test14() // expected-error {{expected ';' after top level declarator}}
95*67e74705SXin Li
96*67e74705SXin Li void test14a();
97*67e74705SXin Li void *test14b = (void*)test14a; // Make sure test14a didn't get skipped.
98*67e74705SXin Li
99*67e74705SXin Li // rdar://problem/8358508
100*67e74705SXin Li long struct X { int x; } test15(); // expected-error {{'long struct' is invalid}}
101*67e74705SXin Li
102*67e74705SXin Li void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}}
103*67e74705SXin Li void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}}
104*67e74705SXin Li void knrNoSemi(i) int i { } // expected-error {{expected ';' at end of declaration}}
105*67e74705SXin Li
106*67e74705SXin Li
107*67e74705SXin Li // PR12595
108*67e74705SXin Li void test18() {
109*67e74705SXin Li int x = 4+(5-12)); // expected-error {{extraneous ')' before ';'}}
110*67e74705SXin Li }
111*67e74705SXin Li
112*67e74705SXin Li enum E1 { e1 }: // expected-error {{expected ';'}}
113*67e74705SXin Li struct EnumBitfield { // expected-warning {{struct without named members is a GNU extension}}
114*67e74705SXin Li enum E2 { e2 } : 4; // ok
115*67e74705SXin Li struct S { int n; }: // expected-error {{expected ';'}}
116*67e74705SXin Li // expected-warning@-1 {{declaration does not declare anything}}
117*67e74705SXin Li
118*67e74705SXin Li };
119*67e74705SXin Li
120*67e74705SXin Li // PR10982
121*67e74705SXin Li enum E11 {
122*67e74705SXin Li A1 = 1,
123*67e74705SXin Li };
124*67e74705SXin Li
125*67e74705SXin Li enum E12 {
126*67e74705SXin Li , // expected-error{{expected identifier}}
127*67e74705SXin Li A2
128*67e74705SXin Li };
129*67e74705SXin Li void func_E12(enum E12 *p) { *p = A2; }
130*67e74705SXin Li
131*67e74705SXin Li enum E13 {
132*67e74705SXin Li 1D, // expected-error{{expected identifier}}
133*67e74705SXin Li A3
134*67e74705SXin Li };
135*67e74705SXin Li void func_E13(enum E13 *p) { *p = A3; }
136*67e74705SXin Li
137*67e74705SXin Li enum E14 {
138*67e74705SXin Li A4 12, // expected-error{{expected '= constant-expression' or end of enumerator definition}}
139*67e74705SXin Li A4a
140*67e74705SXin Li };
141*67e74705SXin Li void func_E14(enum E14 *p) { *p = A4a; }
142*67e74705SXin Li
143*67e74705SXin Li enum E15 {
144*67e74705SXin Li A5=12 4, // expected-error{{expected '}' or ','}}
145*67e74705SXin Li A5a
146*67e74705SXin Li };
147*67e74705SXin Li void func_E15(enum E15 *p) { *p = A5a; }
148*67e74705SXin Li
149*67e74705SXin Li enum E16 {
150*67e74705SXin Li A6; // expected-error{{expected '= constant-expression' or end of enumerator definition}}
151*67e74705SXin Li A6a
152*67e74705SXin Li };
153*67e74705SXin Li
154*67e74705SXin Li int PR20634 = sizeof(struct { int n; } [5]);
155