| Hans Wennborg | 2fb8b91 | 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 | d864daf | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 2 | */ | 
| Chris Lattner | 35da3e2 | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 3 | void test1() { | 
| Chris Lattner | d864daf | 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 | f2c338b | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 20 |  | 
| Chris Lattner | 35da3e2 | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 21 | long long test2;   /* expected-warning {{extension}} */ | 
| Chris Lattner | f2c338b | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 22 |  | 
| Chris Lattner | 35da3e2 | 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 | ac582c5 | 2007-08-29 22:00:19 +0000 | [diff] [blame] | 27 |  | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 28 | int test4 = 0LL;   /* expected-warning {{long long}} */ | 
| Neil Booth | ac582c5 | 2007-08-29 22:00:19 +0000 | [diff] [blame] | 29 |  | 
| Chris Lattner | 7b8134f | 2008-02-10 23:08:00 +0000 | [diff] [blame] | 30 | /* PR1999 */ | 
|  | 31 | void test5(register); | 
|  | 32 |  | 
| Chris Lattner | 287c734 | 2008-02-15 18:02:59 +0000 | [diff] [blame] | 33 | /* PR2041 */ | 
|  | 34 | int *restrict; | 
| Chris Lattner | d2a02fe | 2008-02-19 06:46:10 +0000 | [diff] [blame] | 35 | int *__restrict;  /* expected-error {{expected identifier}} */ | 
| Chris Lattner | 94fc806 | 2008-04-05 05:52:15 +0000 | [diff] [blame] | 36 |  | 
|  | 37 |  | 
|  | 38 | /* Implicit int, always ok */ | 
| Mike Stump | 753d120 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 39 | test6() { return 0; } | 
| Chris Lattner | 9d51f2b | 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 | 3d72297 | 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 | 94fc806 | 2008-04-05 05:52:15 +0000 | [diff] [blame] | 49 |  | 
|  | 50 |  | 
| Chris Lattner | 5825824 | 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 | 0e91b41 | 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 | 5825824 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 62 |  | 
| Chris Lattner | b6ec4e7 | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 63 | /* PR2759 */ | 
| Richard Smith | e434590 | 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 | b6ec4e7 | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 66 |  | 
| Richard Smith | e434590 | 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 | b6ec4e7 | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 69 | } | 
| Eli Friedman | ab2784f | 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 | 4058a84 | 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 | ea7b85b | 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 | 2fb8b91 | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 85 |  | 
| Hans Wennborg | 70a1324 | 2011-12-08 15:56:07 +0000 | [diff] [blame] | 86 | extern int printf(__const char *__restrict __format, ...); | 
| Hans Wennborg | 2fb8b91 | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 87 |  | 
| Hans Wennborg | 70a1324 | 2011-12-08 15:56:07 +0000 | [diff] [blame] | 88 | /* Warn, but don't suggest typo correction. */ | 
| Hans Wennborg | 2fb8b91 | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 89 | void test16() { | 
| Hans Wennborg | 70a1324 | 2011-12-08 15:56:07 +0000 | [diff] [blame] | 90 | printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */ | 
| Hans Wennborg | 2fb8b91 | 2011-12-06 09:46:12 +0000 | [diff] [blame] | 91 | } | 
| John McCall | 5ed3caf | 2012-02-14 19:50:52 +0000 | [diff] [blame] | 92 |  | 
| David Majnemer | 4101621 | 2013-11-02 10:38:05 +0000 | [diff] [blame] | 93 | struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99 feature}} */ | 
| David Chisnall | 07518f2 | 2012-03-16 12:15:37 +0000 | [diff] [blame] | 94 |  | 
| Eli Friedman | c1f0d5b | 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 | 5ed3caf | 2012-02-14 19:50:52 +0000 | [diff] [blame] | 112 | void main() {} /* expected-error {{'main' must return 'int'}} */ | 
| Dmitri Gribenko | 1cd2305 | 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 |  | 
| Enea Zaffanella | c7cb48c | 2013-07-22 19:10:20 +0000 | [diff] [blame] | 119 | struct Test17 { int a; }; | 
|  | 120 | struct Test17 test17_aux(void); | 
|  | 121 |  | 
| Enea Zaffanella | 1aac546 | 2013-07-22 10:58:26 +0000 | [diff] [blame] | 122 | void test17(int v, int w) { | 
|  | 123 | int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */ | 
| Enea Zaffanella | c7cb48c | 2013-07-22 19:10:20 +0000 | [diff] [blame] | 124 | struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */ | 
|  | 125 | struct Test17 t1 = test17_aux(); /* this is allowed */ | 
| Enea Zaffanella | 1aac546 | 2013-07-22 10:58:26 +0000 | [diff] [blame] | 126 | } | 
|  | 127 |  |