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