Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | /* RUN: clang-cc %s -std=c89 -pedantic -fsyntax-only -verify |
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 */ |
| 64 | void test10 (int x[*]); /* expected-warning {{use of C99-specific array features}} */ |
| 65 | void test11 (int x[static 4]); /* expected-warning {{use of C99-specific array features}} */ |
| 66 | |
| 67 | void test12 (int x[const 4]) { /* expected-warning {{use of C99-specific array features}} */ |
| 68 | int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature, accepted as an extension}} */ |
| 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)(); } |