xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/c89.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc /* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration
2f4a2713aSLionel Sambuc  */
test1()3f4a2713aSLionel Sambuc void test1() {
4f4a2713aSLionel Sambuc   {
5f4a2713aSLionel Sambuc     int i;
6f4a2713aSLionel Sambuc     i = i + 1;
7f4a2713aSLionel Sambuc     int j;          /* expected-warning {{mixing declarations and code}} */
8f4a2713aSLionel Sambuc   }
9f4a2713aSLionel Sambuc   {
10f4a2713aSLionel Sambuc     __extension__ int i;
11f4a2713aSLionel Sambuc     i = i + 1;
12f4a2713aSLionel Sambuc     int j;          /* expected-warning {{mixing declarations and code}} */
13f4a2713aSLionel Sambuc   }
14f4a2713aSLionel Sambuc   {
15f4a2713aSLionel Sambuc     int i;
16f4a2713aSLionel Sambuc     i = i + 1;
17f4a2713aSLionel Sambuc     __extension__ int j; /* expected-warning {{mixing declarations and code}} */
18f4a2713aSLionel Sambuc   }
19f4a2713aSLionel Sambuc }
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc long long test2;   /* expected-warning {{extension}} */
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc 
test3(int i)24f4a2713aSLionel Sambuc void test3(int i) {
25f4a2713aSLionel Sambuc   int A[i];        /* expected-warning {{variable length array}} */
26f4a2713aSLionel Sambuc }
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc int test4 = 0LL;   /* expected-warning {{long long}} */
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc /* PR1999 */
31f4a2713aSLionel Sambuc void test5(register);
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc /* PR2041 */
34f4a2713aSLionel Sambuc int *restrict;
35f4a2713aSLionel Sambuc int *__restrict;  /* expected-error {{expected identifier}} */
36f4a2713aSLionel Sambuc 
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc /* Implicit int, always ok */
test6()39f4a2713aSLionel Sambuc test6() { return 0; }
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc /* PR2012 */
42f4a2713aSLionel Sambuc test7;  /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc void test8(int, x);  /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc typedef int sometype;
a(sometype,y)47f4a2713aSLionel Sambuc int a(sometype, y) {return 0;}  /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \
48f4a2713aSLionel Sambuc                                    expected-error {{parameter name omitted}}*/
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc void bar (void *);
f11(z)54f4a2713aSLionel Sambuc void f11 (z)       /* expected-error {{may not have 'void' type}} */
55f4a2713aSLionel Sambuc void z;
56f4a2713aSLionel Sambuc { bar (&z); }
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc typedef void T;
59f4a2713aSLionel Sambuc void foo(T); /* typedef for void is allowed */
60f4a2713aSLionel Sambuc 
foo(void)61f4a2713aSLionel Sambuc void foo(void) {}
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc /* PR2759 */
64f4a2713aSLionel Sambuc void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */
65f4a2713aSLionel Sambuc void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */
66f4a2713aSLionel Sambuc 
test12(int x[const4])67f4a2713aSLionel Sambuc void test12 (int x[const 4]) { /* expected-warning {{qualifier in array size is a C99 feature}} */
68f4a2713aSLionel Sambuc   int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature}} */
69f4a2713aSLionel Sambuc }
70f4a2713aSLionel Sambuc 
71f4a2713aSLionel Sambuc /* PR4074 */
72f4a2713aSLionel Sambuc struct test13 {
73f4a2713aSLionel Sambuc   int X[23];
74f4a2713aSLionel Sambuc } test13a();
75f4a2713aSLionel Sambuc 
test13b()76f4a2713aSLionel Sambuc void test13b() {
77f4a2713aSLionel Sambuc   int a = test13a().X[1]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
78f4a2713aSLionel Sambuc   int b = 1[test13a().X]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
79f4a2713aSLionel Sambuc }
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc /* Make sure we allow *test14 as a "function designator" */
test14()82f4a2713aSLionel Sambuc int test14() { return (&*test14)(); }
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
85f4a2713aSLionel Sambuc 
86f4a2713aSLionel Sambuc extern int printf(__const char *__restrict __format, ...);
87f4a2713aSLionel Sambuc 
88f4a2713aSLionel Sambuc /* Warn, but don't suggest typo correction. */
test16()89f4a2713aSLionel Sambuc void test16() {
90f4a2713aSLionel Sambuc   printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
91f4a2713aSLionel Sambuc }
92f4a2713aSLionel Sambuc 
93f4a2713aSLionel Sambuc struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99 feature}} */
94f4a2713aSLionel Sambuc 
95f4a2713aSLionel Sambuc /* Duplicated type-qualifiers aren't allowed by C90 */
96f4a2713aSLionel Sambuc const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
97f4a2713aSLionel Sambuc typedef volatile int vol_int;
98f4a2713aSLionel Sambuc volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
99f4a2713aSLionel Sambuc typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
100f4a2713aSLionel Sambuc const int * const c;
101f4a2713aSLionel Sambuc 
102f4a2713aSLionel Sambuc typedef const int CI;
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */
105f4a2713aSLionel Sambuc 
106f4a2713aSLionel Sambuc typedef CI array_of_CI[5];
107f4a2713aSLionel Sambuc const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc typedef CI *array_of_pointer_to_CI[5];
110f4a2713aSLionel Sambuc const array_of_pointer_to_CI mine3;
111f4a2713aSLionel Sambuc 
main()112f4a2713aSLionel Sambuc void main() {} /* expected-error {{'main' must return 'int'}} */
113f4a2713aSLionel Sambuc 
main()114*0a6a1f1dSLionel Sambuc const int main() {} /* expected-error {{'main' must return 'int'}} */
115*0a6a1f1dSLionel Sambuc 
116f4a2713aSLionel Sambuc long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
117f4a2713aSLionel Sambuc          -42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
118f4a2713aSLionel Sambuc unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
119f4a2713aSLionel Sambuc                    42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
120f4a2713aSLionel Sambuc 
121f4a2713aSLionel Sambuc struct Test17 { int a; };
122f4a2713aSLionel Sambuc struct Test17 test17_aux(void);
123f4a2713aSLionel Sambuc 
test17(int v,int w)124f4a2713aSLionel Sambuc void test17(int v, int w) {
125f4a2713aSLionel Sambuc   int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
126f4a2713aSLionel Sambuc   struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
127f4a2713aSLionel Sambuc   struct Test17 t1 = test17_aux(); /* this is allowed */
128f4a2713aSLionel Sambuc }
129f4a2713aSLionel Sambuc 
130