blob: c9e81f1c41ca9877cb6a120df9dea65c044de905 [file] [log] [blame]
Hans Wennborg2fb8b912011-12-06 09:46:12 +00001/* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration
Chris Lattnerd864daf2007-08-27 04:29:41 +00002 */
Chris Lattner35da3e22007-08-28 16:54:00 +00003void test1() {
Chris Lattnerd864daf2007-08-27 04:29:41 +00004 {
5 int i;
6 i = i + 1;
7 int j; /* expected-warning {{mixing declarations and code}} */
8 }
9 {
10 __extension__ int i;
11 i = i + 1;
12 int j; /* expected-warning {{mixing declarations and code}} */
13 }
14 {
15 int i;
16 i = i + 1;
17 __extension__ int j; /* expected-warning {{mixing declarations and code}} */
18 }
19}
Chris Lattnerf2c338b2007-08-28 16:40:32 +000020
Chris Lattner35da3e22007-08-28 16:54:00 +000021long long test2; /* expected-warning {{extension}} */
Chris Lattnerf2c338b2007-08-28 16:40:32 +000022
Chris Lattner35da3e22007-08-28 16:54:00 +000023
24void test3(int i) {
25 int A[i]; /* expected-warning {{variable length array}} */
26}
Neil Boothac582c52007-08-29 22:00:19 +000027
Mike Stump11289f42009-09-09 15:08:12 +000028int test4 = 0LL; /* expected-warning {{long long}} */
Neil Boothac582c52007-08-29 22:00:19 +000029
Chris Lattner7b8134f2008-02-10 23:08:00 +000030/* PR1999 */
31void test5(register);
32
Chris Lattner287c7342008-02-15 18:02:59 +000033/* PR2041 */
34int *restrict;
Chris Lattnerd2a02fe2008-02-19 06:46:10 +000035int *__restrict; /* expected-error {{expected identifier}} */
Chris Lattner94fc8062008-04-05 05:52:15 +000036
37
38/* Implicit int, always ok */
Mike Stump753d1202009-07-22 00:43:08 +000039test6() { return 0; }
Chris Lattner9d51f2b2008-04-05 06:32:51 +000040
41/* PR2012 */
42test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
43
44void test8(int, x); /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
45
46typedef int sometype;
Chris Lattner3d722972008-12-17 07:32:46 +000047int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \
48 expected-error {{parameter name omitted}}*/
Chris Lattner94fc8062008-04-05 05:52:15 +000049
50
Chris Lattner58258242008-04-10 02:22:51 +000051
52
53void bar (void *);
54void f11 (z) /* expected-error {{may not have 'void' type}} */
55void z;
56{ bar (&z); }
57
58typedef void T;
Chris Lattner0e91b412008-04-10 02:26:16 +000059void foo(T); /* typedef for void is allowed */
60
61void foo(void) {}
Chris Lattner58258242008-04-10 02:22:51 +000062
Chris Lattnerb6ec4e72008-12-18 06:50:14 +000063/* PR2759 */
Richard Smithe4345902011-12-29 21:57:33 +000064void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */
65void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */
Chris Lattnerb6ec4e72008-12-18 06:50:14 +000066
Richard Smithe4345902011-12-29 21:57:33 +000067void test12 (int x[const 4]) { /* expected-warning {{qualifier in array size is a C99 feature}} */
68 int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature}} */
Chris Lattnerb6ec4e72008-12-18 06:50:14 +000069}
Eli Friedmanab2784f2009-04-25 23:46:54 +000070
71/* PR4074 */
72struct test13 {
73 int X[23];
74} test13a();
75
76void test13b() {
77 int a = test13a().X[1]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
78 int b = 1[test13a().X]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
79}
80
Eli Friedman4058a842009-04-28 17:59:09 +000081/* Make sure we allow *test14 as a "function designator" */
82int test14() { return (&*test14)(); }
Eli Friedmanea7b85b2011-04-24 22:14:22 +000083
84int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
Hans Wennborg2fb8b912011-12-06 09:46:12 +000085
Hans Wennborg70a13242011-12-08 15:56:07 +000086extern int printf(__const char *__restrict __format, ...);
Hans Wennborg2fb8b912011-12-06 09:46:12 +000087
Hans Wennborg70a13242011-12-08 15:56:07 +000088/* Warn, but don't suggest typo correction. */
Hans Wennborg2fb8b912011-12-06 09:46:12 +000089void test16() {
Hans Wennborg70a13242011-12-08 15:56:07 +000090 printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
Hans Wennborg2fb8b912011-12-06 09:46:12 +000091}
John McCall5ed3caf2012-02-14 19:50:52 +000092
David Majnemer41016212013-11-02 10:38:05 +000093struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99 feature}} */
David Chisnall07518f22012-03-16 12:15:37 +000094
Eli Friedmanc1f0d5b2012-04-05 22:47:34 +000095/* Duplicated type-qualifiers aren't allowed by C90 */
96const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
97typedef volatile int vol_int;
98volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
99typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
100const int * const c;
101
102typedef const int CI;
103
104const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */
105
106typedef CI array_of_CI[5];
107const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */
108
109typedef CI *array_of_pointer_to_CI[5];
110const array_of_pointer_to_CI mine3;
111
John McCall5ed3caf2012-02-14 19:50:52 +0000112void main() {} /* expected-error {{'main' must return 'int'}} */
Dmitri Gribenko1cd23052012-09-24 18:19:21 +0000113
Alp Toker70fc29c2014-07-02 07:07:20 +0000114const int main() {} /* expected-error {{'main' must return 'int'}} */
115
Dmitri Gribenko1cd23052012-09-24 18:19:21 +0000116long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
117 -42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
118unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
119 42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
120
Enea Zaffanellac7cb48c2013-07-22 19:10:20 +0000121struct Test17 { int a; };
122struct Test17 test17_aux(void);
123
Enea Zaffanella1aac5462013-07-22 10:58:26 +0000124void test17(int v, int w) {
125 int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
Enea Zaffanellac7cb48c2013-07-22 19:10:20 +0000126 struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
127 struct Test17 t1 = test17_aux(); /* this is allowed */
Enea Zaffanella1aac5462013-07-22 10:58:26 +0000128}
129