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