declarators.c revision 9e46b8cfb3e6c6feab5664744f52f06a40f9566b
1// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic 2 3extern int a1[]; 4 5void f0(); 6void f1(int [*]); 7void f2(int [const *]); 8void f3(int [volatile const*]); 9int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */ 10 11char ((((*X)))); 12 13void (*signal(int, void (*)(int)))(int); 14 15int aaaa, ***C, * const D, B(int); 16 17int *A; 18 19struct str; 20 21void test2(int *P, int A) { 22 struct str; 23 24 // Hard case for array decl, not Array[*]. 25 int Array[*(int*)P+A]; 26} 27 28typedef int atype; 29void test3(x, 30 atype /* expected-error {{unexpected type name 'atype': expected identifier}} */ 31 ) int x, atype; {} 32 33void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */ 34 35 36// PR3031 37int (test5), ; // expected-error {{expected identifier or '('}} 38 39 40 41// PR3963 & rdar://6759604 - test error recovery for mistyped "typenames". 42 43foo_t *d; // expected-error {{unknown type name 'foo_t'}} 44foo_t a; // expected-error {{unknown type name 'foo_t'}} 45int test6() { return a; } // a should be declared. 46 47// Use of tagged type without tag. rdar://6783347 48struct xyz { int y; }; 49enum myenum { ASDFAS }; 50xyz b; // expected-error {{must use 'struct' tag to refer to type 'xyz'}} 51myenum c; // expected-error {{must use 'enum' tag to refer to type 'myenum'}} 52 53float *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. 56 return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}} 57} 58 59struct xyz test8() { return a; } // a should be be marked invalid, no diag. 60 61 62// Verify that implicit int still works. 63static f; // expected-warning {{type specifier missing, defaults to 'int'}} 64static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}} 65static h // expected-warning {{type specifier missing, defaults to 'int'}} 66 __asm__("foo"); 67 68 69struct 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}; 74 75// PR6208 76struct test10 { int a; } static test10x; 77struct test11 { int a; } const test11x; 78 79// PR6216 80void test12() { 81 (void)__builtin_offsetof(struct { char c; int i; }, i); 82} 83 84// rdar://7608537 85struct test13 { int a; } (test13x); 86 87// <rdar://problem/8044088> 88struct X<foo::int> { }; // expected-error{{expected identifier or '('}} 89 90 91// PR7617 - error recovery on missing ;. 92 93void test14() // expected-error {{expected ';' after top level declarator}} 94 95void test14a(); 96void *test14b = (void*)test14a; // Make sure test14a didn't get skipped. 97 98// rdar://problem/8358508 99long struct X {} test15(); // expected-error {{'long struct' is invalid}} 100