Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | |
| 3 | extern int a1[]; |
| 4 | |
| 5 | void f0(); |
| 6 | void f1(int [*]); |
| 7 | void f2(int [const *]); |
| 8 | void f3(int [volatile const*]); |
Chris Lattner | d658b56 | 2008-04-05 06:32:51 +0000 | [diff] [blame] | 9 | int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */ |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 10 | |
| 11 | char ((((*X)))); |
| 12 | |
| 13 | void (*signal(int, void (*)(int)))(int); |
| 14 | |
Chris Lattner | 33c6ebe | 2009-04-12 22:12:26 +0000 | [diff] [blame] | 15 | int aaaa, ***C, * const D, B(int); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | |
| 17 | int *A; |
| 18 | |
| 19 | struct str; |
| 20 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 21 | void test2(int *P, int A) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | struct str; |
| 23 | |
| 24 | // Hard case for array decl, not Array[*]. |
| 25 | int Array[*(int*)P+A]; |
| 26 | } |
| 27 | |
Chris Lattner | aaf9ddb | 2008-04-06 06:47:48 +0000 | [diff] [blame] | 28 | typedef int atype; |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 29 | void test3(x, |
| 30 | atype /* expected-error {{unexpected type name 'atype': expected identifier}} */ |
| 31 | ) int x, atype; {} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 33 | void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */ |
Chris Lattner | 3825c2e | 2008-04-06 06:50:56 +0000 | [diff] [blame] | 34 | |
Chris Lattner | 1f6f54b | 2008-11-11 06:13:16 +0000 | [diff] [blame] | 35 | |
| 36 | // PR3031 |
| 37 | int (test5), ; // expected-error {{expected identifier or '('}} |
| 38 | |
Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | // PR3963 & rdar://6759604 - test error recovery for mistyped "typenames". |
| 42 | |
Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 43 | foo_t *d; // expected-error {{unknown type name 'foo_t'}} |
Chris Lattner | 33c6ebe | 2009-04-12 22:12:26 +0000 | [diff] [blame] | 44 | foo_t a; // expected-error {{unknown type name 'foo_t'}} |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 45 | int test6() { return a; } // a should be declared. |
Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 47 | // Use of tagged type without tag. rdar://6783347 |
| 48 | struct xyz { int y; }; |
| 49 | enum myenum { ASDFAS }; |
John McCall | 23e907a | 2010-02-14 01:03:10 +0000 | [diff] [blame] | 50 | xyz b; // expected-error {{must use 'struct' tag to refer to type 'xyz'}} |
| 51 | myenum c; // expected-error {{must use 'enum' tag to refer to type 'myenum'}} |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 52 | |
| 53 | float *test7() { |
| 54 | // We should recover 'b' by parsing it with a valid type of "struct xyz", which |
| 55 | // allows us to diagnose other bad things done with y, such as this. |
Douglas Gregor | d4eea83 | 2010-04-09 00:35:39 +0000 | [diff] [blame] | 56 | return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}} |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Chris Lattner | 33c6ebe | 2009-04-12 22:12:26 +0000 | [diff] [blame] | 59 | struct xyz test8() { return a; } // a should be be marked invalid, no diag. |
| 60 | |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 61 | |
| 62 | // Verify that implicit int still works. |
Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 63 | static f; // expected-warning {{type specifier missing, defaults to 'int'}} |
| 64 | static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}} |
| 65 | static h // expected-warning {{type specifier missing, defaults to 'int'}} |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 66 | __asm__("foo"); |
Chris Lattner | 3e156ad | 2010-02-02 00:37:27 +0000 | [diff] [blame] | 67 | |
| 68 | |
| 69 | struct test9 { |
| 70 | int x // expected-error {{expected ';' at end of declaration list}} |
| 71 | int y; |
| 72 | int z // expected-warning {{expected ';' at end of declaration list}} |
| 73 | }; |
Chris Lattner | 99c9520 | 2010-02-02 17:32:27 +0000 | [diff] [blame] | 74 | |
| 75 | // PR6208 |
| 76 | struct test10 { int a; } static test10x; |
| 77 | struct test11 { int a; } const test11x; |
Chris Lattner | 16acfee | 2010-02-03 01:45:03 +0000 | [diff] [blame] | 78 | |
| 79 | // PR6216 |
| 80 | void test12() { |
| 81 | (void)__builtin_offsetof(struct { char c; int i; }, i); |
| 82 | } |
Chris Lattner | c2e1c1a | 2010-02-03 20:41:24 +0000 | [diff] [blame] | 83 | |
| 84 | // rdar://7608537 |
| 85 | struct test13 { int a; } (test13x); |
Douglas Gregor | 5ee3734 | 2010-05-30 22:30:21 +0000 | [diff] [blame] | 86 | |
| 87 | // <rdar://problem/8044088> |
| 88 | struct X<foo::int> { }; // expected-error{{expected identifier or '('}} |
Chris Lattner | 004659a | 2010-07-11 22:42:07 +0000 | [diff] [blame] | 89 | |
| 90 | |
| 91 | // PR7617 - error recovery on missing ;. |
| 92 | |
Chris Lattner | 9b3215d | 2010-07-11 22:46:04 +0000 | [diff] [blame] | 93 | void test14() // expected-error {{expected ';' after top level declarator}} |
Chris Lattner | 004659a | 2010-07-11 22:42:07 +0000 | [diff] [blame] | 94 | |
| 95 | void test14a(); |
| 96 | void *test14b = (void*)test14a; // Make sure test14a didn't get skipped. |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame^] | 97 | |
| 98 | // rdar://problem/8358508 |
| 99 | long struct X {} test15(); // expected-error {{'long struct' is invalid}} |