Hans Wennborg | 122de3e | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 1 | /* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration |
Chris Lattner | c30ebfb | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 2 | */ |
Chris Lattner | 94f81fd | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 3 | void test1() { |
Chris Lattner | c30ebfb | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 4 | { |
| 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 Lattner | b23deda | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 20 | |
Chris Lattner | 94f81fd | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 21 | long long test2; /* expected-warning {{extension}} */ |
Chris Lattner | b23deda | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 22 | |
Chris Lattner | 94f81fd | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 23 | |
| 24 | void test3(int i) { |
| 25 | int A[i]; /* expected-warning {{variable length array}} */ |
| 26 | } |
Neil Booth | b944951 | 2007-08-29 22:00:19 +0000 | [diff] [blame] | 27 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 28 | int test4 = 0LL; /* expected-warning {{long long}} */ |
Neil Booth | b944951 | 2007-08-29 22:00:19 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 99d724f | 2008-02-10 23:08:00 +0000 | [diff] [blame] | 30 | /* PR1999 */ |
| 31 | void test5(register); |
| 32 | |
Chris Lattner | 3e5849e | 2008-02-15 18:02:59 +0000 | [diff] [blame] | 33 | /* PR2041 */ |
| 34 | int *restrict; |
Chris Lattner | 49581f4 | 2008-02-19 06:46:10 +0000 | [diff] [blame] | 35 | int *__restrict; /* expected-error {{expected identifier}} */ |
Chris Lattner | a798ebc | 2008-04-05 05:52:15 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | /* Implicit int, always ok */ |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 39 | test6() { return 0; } |
Chris Lattner | d658b56 | 2008-04-05 06:32:51 +0000 | [diff] [blame] | 40 | |
| 41 | /* PR2012 */ |
| 42 | test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */ |
| 43 | |
| 44 | void test8(int, x); /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */ |
| 45 | |
| 46 | typedef int sometype; |
Chris Lattner | 777f07b | 2008-12-17 07:32:46 +0000 | [diff] [blame] | 47 | int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \ |
| 48 | expected-error {{parameter name omitted}}*/ |
Chris Lattner | a798ebc | 2008-04-05 05:52:15 +0000 | [diff] [blame] | 49 | |
| 50 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | void bar (void *); |
| 54 | void f11 (z) /* expected-error {{may not have 'void' type}} */ |
| 55 | void z; |
| 56 | { bar (&z); } |
| 57 | |
| 58 | typedef void T; |
Chris Lattner | def026a | 2008-04-10 02:26:16 +0000 | [diff] [blame] | 59 | void foo(T); /* typedef for void is allowed */ |
| 60 | |
| 61 | void foo(void) {} |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 62 | |
Chris Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 63 | /* PR2759 */ |
Richard Smith | d7c56e1 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 64 | void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */ |
| 65 | void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */ |
Chris Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 66 | |
Richard Smith | d7c56e1 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 67 | void 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 Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 69 | } |
Eli Friedman | 7c32f8e | 2009-04-25 23:46:54 +0000 | [diff] [blame] | 70 | |
| 71 | /* PR4074 */ |
| 72 | struct test13 { |
| 73 | int X[23]; |
| 74 | } test13a(); |
| 75 | |
| 76 | void 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 Friedman | 9895d88 | 2009-04-28 17:59:09 +0000 | [diff] [blame] | 81 | /* Make sure we allow *test14 as a "function designator" */ |
| 82 | int test14() { return (&*test14)(); } |
Eli Friedman | a47317b | 2011-04-24 22:14:22 +0000 | [diff] [blame] | 83 | |
| 84 | int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */ |
Hans Wennborg | 122de3e | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 85 | |
Hans Wennborg | e3ca33a | 2011-12-08 15:56:07 +0000 | [diff] [blame] | 86 | extern int printf(__const char *__restrict __format, ...); |
Hans Wennborg | 122de3e | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 87 | |
Hans Wennborg | e3ca33a | 2011-12-08 15:56:07 +0000 | [diff] [blame] | 88 | /* Warn, but don't suggest typo correction. */ |
Hans Wennborg | 122de3e | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 89 | void test16() { |
Hans Wennborg | e3ca33a | 2011-12-08 15:56:07 +0000 | [diff] [blame] | 90 | printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */ |
Hans Wennborg | 122de3e | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 91 | } |
John McCall | 75d8ba3 | 2012-02-14 19:50:52 +0000 | [diff] [blame] | 92 | |
David Chisnall | 0961a01 | 2012-03-16 12:15:37 +0000 | [diff] [blame] | 93 | struct x { int x,y[]; }; /* expected-warning {{Flexible array members are a C99-specific feature}} */ |
| 94 | |
Eli Friedman | bc1029b | 2012-04-05 22:47:34 +0000 | [diff] [blame] | 95 | /* Duplicated type-qualifiers aren't allowed by C90 */ |
| 96 | const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */ |
| 97 | typedef volatile int vol_int; |
| 98 | volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */ |
| 99 | typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */ |
| 100 | const int * const c; |
| 101 | |
| 102 | typedef const int CI; |
| 103 | |
| 104 | const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */ |
| 105 | |
| 106 | typedef CI array_of_CI[5]; |
| 107 | const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */ |
| 108 | |
| 109 | typedef CI *array_of_pointer_to_CI[5]; |
| 110 | const array_of_pointer_to_CI mine3; |
| 111 | |
John McCall | 75d8ba3 | 2012-02-14 19:50:52 +0000 | [diff] [blame] | 112 | void main() {} /* expected-error {{'main' must return 'int'}} */ |
Dmitri Gribenko | e3b136b | 2012-09-24 18:19:21 +0000 | [diff] [blame] | 113 | |
| 114 | long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ |
| 115 | -42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ |
| 116 | unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ |
| 117 | 42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ |
| 118 | |