| 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic |
| 2 | |
| 3 | extern int a1[]; |
| 4 | |
| 5 | void f0(); |
| 6 | void f1(int [*]); |
| 7 | void f2(int [const *]); |
| 8 | void f3(int [volatile const*]); |
| 9 | int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */ |
| 10 | int f5(int [static]); /* expected-error {{'static' may not be used without an array size}} */ |
| 11 | |
| 12 | char ((((*X)))); |
| 13 | |
| 14 | void (*signal(int, void (*)(int)))(int); |
| 15 | |
| 16 | int aaaa, ***C, * const D, B(int); |
| 17 | |
| 18 | int *A; |
| 19 | |
| 20 | struct str; |
| 21 | |
| 22 | void test2(int *P, int A) { |
| 23 | struct str; |
| 24 | |
| 25 | // Hard case for array decl, not Array[*]. |
| 26 | int Array[*(int*)P+A]; |
| 27 | } |
| 28 | |
| 29 | typedef int atype; |
| 30 | void test3(x, |
| 31 | atype /* expected-error {{unexpected type name 'atype': expected identifier}} */ |
| 32 | ) int x, atype; {} |
| 33 | |
| 34 | void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */ |
| 35 | |
| 36 | |
| 37 | // PR3031 |
| 38 | int (test5), ; // expected-error {{expected identifier or '('}} |
| 39 | |
| 40 | |
| 41 | |
| 42 | // PR3963 & rdar://6759604 - test error recovery for mistyped "typenames". |
| 43 | |
| 44 | foo_t *d; // expected-error {{unknown type name 'foo_t'}} |
| 45 | foo_t a; // expected-error {{unknown type name 'foo_t'}} |
| 46 | int test6() { return a; } // a should be declared. |
| 47 | |
| 48 | // Use of tagged type without tag. rdar://6783347 |
| 49 | struct xyz { int y; }; |
| 50 | enum myenum { ASDFAS }; |
| 51 | xyz b; // expected-error {{must use 'struct' tag to refer to type 'xyz'}} |
| 52 | myenum c; // expected-error {{must use 'enum' tag to refer to type 'myenum'}} |
| 53 | |
| 54 | float *test7() { |
| 55 | // We should recover 'b' by parsing it with a valid type of "struct xyz", which |
| 56 | // allows us to diagnose other bad things done with y, such as this. |
| 57 | return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}} |
| 58 | } |
| 59 | |
| 60 | struct xyz test8() { return a; } // a should be be marked invalid, no diag. |
| 61 | |
| 62 | |
| 63 | // Verify that implicit int still works. |
| 64 | static f; // expected-warning {{type specifier missing, defaults to 'int'}} |
| 65 | static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}} |
| 66 | static h // expected-warning {{type specifier missing, defaults to 'int'}} |
| 67 | __asm__("foo"); |
| 68 | |
| 69 | |
| 70 | struct test9 { |
| 71 | int x // expected-error {{expected ';' at end of declaration list}} |
| 72 | int y; |
| 73 | int z // expected-warning {{expected ';' at end of declaration list}} |
| 74 | }; |
| 75 | |
| 76 | // PR6208 |
| 77 | struct test10 { int a; } static test10x; |
| 78 | struct test11 { int a; } const test11x; |
| 79 | |
| 80 | // PR6216 |
| 81 | void test12() { |
| 82 | (void)__builtin_offsetof(struct { char c; int i; }, i); |
| 83 | } |
| 84 | |
| 85 | // rdar://7608537 |
| 86 | struct test13 { int a; } (test13x); |
| 87 | |
| 88 | // <rdar://problem/8044088> |
| 89 | struct X<foo::int> { }; // expected-error{{expected identifier or '('}} |
| 90 | |
| 91 | |
| 92 | // PR7617 - error recovery on missing ;. |
| 93 | |
| 94 | void test14() // expected-error {{expected ';' after top level declarator}} |
| 95 | |
| 96 | void test14a(); |
| 97 | void *test14b = (void*)test14a; // Make sure test14a didn't get skipped. |
| 98 | |
| 99 | // rdar://problem/8358508 |
| 100 | long struct X { int x; } test15(); // expected-error {{'long struct' is invalid}} |
| 101 | |
| 102 | void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}} |
| 103 | void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}} |
| 104 | void knrNoSemi(i) int i { } // expected-error {{expected ';' at end of declaration}} |
| 105 | |
| 106 | |
| 107 | // PR12595 |
| 108 | void test18() { |
| 109 | int x = 4+(5-12)); // expected-error {{extraneous ')' before ';'}} |
| 110 | } |
| 111 | |
| 112 | enum E1 { e1 }: // expected-error {{expected ';'}} |
| 113 | struct EnumBitfield { // expected-warning {{struct without named members is a GNU extension}} |
| 114 | enum E2 { e2 } : 4; // ok |
| 115 | struct S { int n; }: // expected-error {{expected ';'}} |
| 116 | // expected-warning@-1 {{declaration does not declare anything}} |
| 117 | |
| 118 | }; |
| 119 | |
| 120 | // PR10982 |
| 121 | enum E11 { |
| 122 | A1 = 1, |
| 123 | }; |
| 124 | |
| 125 | enum E12 { |
| 126 | , // expected-error{{expected identifier}} |
| 127 | A2 |
| 128 | }; |
| 129 | void func_E12(enum E12 *p) { *p = A2; } |
| 130 | |
| 131 | enum E13 { |
| 132 | 1D, // expected-error{{expected identifier}} |
| 133 | A3 |
| 134 | }; |
| 135 | void func_E13(enum E13 *p) { *p = A3; } |
| 136 | |
| 137 | enum E14 { |
| 138 | A4 12, // expected-error{{expected '= constant-expression' or end of enumerator definition}} |
| 139 | A4a |
| 140 | }; |
| 141 | void func_E14(enum E14 *p) { *p = A4a; } |
| 142 | |
| 143 | enum E15 { |
| 144 | A5=12 4, // expected-error{{expected '}' or ','}} |
| 145 | A5a |
| 146 | }; |
| 147 | void func_E15(enum E15 *p) { *p = A5a; } |
| 148 | |
| 149 | enum E16 { |
| 150 | A6; // expected-error{{expected '= constant-expression' or end of enumerator definition}} |
| 151 | A6a |
| 152 | }; |
| 153 | |
| 154 | int PR20634 = sizeof(struct { int n; } [5]); |
| 155 | |