[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / clang / test / Sema / c89.c
blobe89f4fd684c49aed0e85338dc30dc5425cb674a3
1 /* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration -Wno-strict-prototypes
2 */
3 void test1(void) {
5 int i;
6 i = i + 1;
7 int j; /* expected-warning {{mixing declarations and code}} */
10 __extension__ int i;
11 i = i + 1;
12 int j; /* expected-warning {{mixing declarations and code}} */
15 int i;
16 i = i + 1;
17 __extension__ int j; /* expected-warning {{mixing declarations and code}} */
21 long long test2; /* expected-warning {{extension}} */
24 void test3(int i) {
25 int A[i]; /* expected-warning {{variable length array}} */
28 int test4 = 0LL; /* expected-warning {{long long}} */
30 /* PR1999 */
31 void test5(register);
33 /* PR2041 */
34 int *restrict;
35 int *__restrict; /* expected-error {{expected identifier}} */
38 /* Implicit int, always ok */
39 test6(void) { return 0; }
41 /* PR2012 */
42 test7;
44 void test8(int, x);
46 typedef int sometype;
47 int a(sometype, y) {return 0;} /* expected-warning {{omitting the parameter name in a function definition is a C23 extension}}*/
49 void bar (void *);
50 void f11 (z) /* expected-error {{may not have 'void' type}} */
51 void z;
52 { bar (&z); }
54 typedef void T;
55 void foo(T); /* typedef for void is allowed */
57 void foo(void) {}
59 /* PR2759 */
60 void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */
61 void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */
63 void test12 (int x[const 4]) { /* expected-warning {{qualifier in array size is a C99 feature}} */
64 int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature}} */
67 /* PR4074 */
68 struct test13 {
69 int X[23];
70 } test13a();
72 void test13b() {
73 int a = test13a().X[1]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
74 int b = 1[test13a().X]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
77 /* Make sure we allow *test14 as a "function designator" */
78 int test14(void) { return (&*test14)(); }
80 int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
82 extern int printf(__const char *__restrict __format, ...);
84 /* Warn, but don't suggest typo correction. */
85 void test16(void) {
86 printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
89 struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99 feature}} */
91 /* Duplicated type-qualifiers aren't allowed by C90 */
92 const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
93 typedef volatile int vol_int;
94 volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
95 typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
96 const int * const c;
98 typedef const int CI;
100 const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */
102 typedef CI array_of_CI[5];
103 const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */
105 typedef CI *array_of_pointer_to_CI[5];
106 const array_of_pointer_to_CI mine3;
108 void main(void) {} /* expected-error {{'main' must return 'int'}} */
110 const int main(void) {} /* expected-error {{'main' must return 'int'}} */
112 long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
113 -42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
114 unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
115 42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
117 struct Test17 { int a; };
118 struct Test17 test17_aux(void);
120 void test17(int v, int w) {
121 int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
122 struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
123 struct Test17 t1 = test17_aux(); /* this is allowed */