llvm-project/clang/test/Parser/declarators.c

151 lines
4.0 KiB
C
Raw Normal View History

// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
2006-08-07 02:22:00 +08:00
extern int a1[];
2006-08-07 02:22:00 +08:00
void f0();
void f1(int [*]);
void f2(int [const *]);
void f3(int [volatile const*]);
int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */
2006-08-07 02:22:00 +08:00
char ((((*X))));
void (*signal(int, void (*)(int)))(int);
int aaaa, ***C, * const D, B(int);
2006-08-07 02:22:00 +08:00
int *A;
struct str;
2009-07-22 08:43:08 +08:00
void test2(int *P, int A) {
struct str;
// Hard case for array decl, not Array[*].
2006-08-13 02:40:31 +08:00
int Array[*(int*)P+A];
}
typedef int atype;
2009-07-22 08:43:08 +08:00
void test3(x,
atype /* expected-error {{unexpected type name 'atype': expected identifier}} */
) int x, atype; {}
2009-07-22 08:43:08 +08:00
void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */
// PR3031
int (test5), ; // expected-error {{expected identifier or '('}}
// PR3963 & rdar://6759604 - test error recovery for mistyped "typenames".
foo_t *d; // expected-error {{unknown type name 'foo_t'}}
foo_t a; // expected-error {{unknown type name 'foo_t'}}
int test6() { return a; } // a should be declared.
// Use of tagged type without tag. rdar://6783347
struct xyz { int y; };
enum myenum { ASDFAS };
xyz b; // expected-error {{must use 'struct' tag to refer to type 'xyz'}}
myenum c; // expected-error {{must use 'enum' tag to refer to type 'myenum'}}
float *test7() {
// We should recover 'b' by parsing it with a valid type of "struct xyz", which
// allows us to diagnose other bad things done with y, such as this.
return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}}
}
struct xyz test8() { return a; } // a should be be marked invalid, no diag.
// Verify that implicit int still works.
static f; // expected-warning {{type specifier missing, defaults to 'int'}}
static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}}
static h // expected-warning {{type specifier missing, defaults to 'int'}}
Simplify the scheme used for keywords, and change the classification scheme to be more useful. The new scheme introduces a set of categories that should be more readable, and also reflects what we want to consider as an extension more accurately. Specifically, it makes the "what is a keyword" determination accurately reflect whether the keyword is a GNU or Microsoft extension. I also introduced separate flags for keyword aliases; this is useful because the classification of the aliases is mostly unrelated to the classification of the original keyword. This patch treats anything that's in the implementation namespace (prefixed with "__", or "_X" where "X" is any upper-case letter) as a keyword without marking it as an extension. This is consistent with the standards in that an implementation is allowed to define arbitrary extensions in the implementation namespace without violating the standard. This gets rid of all the nasty "extension used" warnings for stuff like __attribute__ in -pedantic mode. We still warn for extensions outside of the the implementation namespace, like typeof. If someone wants to implement -Wextensions or something like that, we could add additional information to the keyword table. This also removes processing for the unused "Boolean" language option; such an extension isn't supported on any other C implementation, so I don't see any point to adding it. The changes to test/CodeGen/inline.c are required because previously, we weren't actually disabling the "inline" keyword in -std=c89 mode. I'll remove Boolean and NoExtensions from LangOptions in a follow-up commit. llvm-svn: 70281
2009-04-28 11:13:54 +08:00
__asm__("foo");
struct test9 {
int x // expected-error {{expected ';' at end of declaration list}}
int y;
int z // expected-warning {{expected ';' at end of declaration list}}
};
// PR6208
struct test10 { int a; } static test10x;
struct test11 { int a; } const test11x;
2010-02-03 09:45:03 +08:00
// PR6216
void test12() {
(void)__builtin_offsetof(struct { char c; int i; }, i);
}
// rdar://7608537
struct test13 { int a; } (test13x);
// <rdar://problem/8044088>
struct X<foo::int> { }; // expected-error{{expected identifier or '('}}
// PR7617 - error recovery on missing ;.
void test14() // expected-error {{expected ';' after top level declarator}}
void test14a();
void *test14b = (void*)test14a; // Make sure test14a didn't get skipped.
// rdar://problem/8358508
long struct X { int x; } test15(); // expected-error {{'long struct' is invalid}}
void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}}
void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}}
Fix bungled parse recovery in K&R function declarations void knrNoSemi(i) int i { } Adherents of The C Programming Language unfortunate enough to miss a semicolon as above would be met with a cascade of errors spanning the remainder of the TU. This patch introduces a beautiful parse error recovery, complete with helpful FixIt to restore sanity. Before (output redacted for brevity): error: 'error' diagnostics seen but not expected: File declarators.c Line 119: declaration does not declare a parameter File declarators.c Line 123: declaration does not declare a parameter File declarators.c Line 127: parameter named 'func_E12' is missing File declarators.c Line 127: expected ';' at end of declaration File declarators.c Line 133: parameter named 'func_E13' is missing File declarators.c Line 133: expected ';' at end of declaration File declarators.c Line 139: parameter named 'func_E14' is missing File declarators.c Line 139: expected ';' at end of declaration File declarators.c Line 145: parameter named 'func_E15' is missing File declarators.c Line 145: expected ';' at end of declaration File declarators.c Line 150: expected function body after function declarator File declarators.c Line 119: declaration of 'enum E11' will not be visible outside of this function File declarators.c Line 123: declaration of 'enum E12' will not be visible outside of this function File declarators.c Line 133: ISO C forbids forward references to 'enum' types File declarators.c Line 133: declaration of 'enum E13' will not be visible outside of this function File declarators.c Line 139: ISO C forbids forward references to 'enum' types File declarators.c Line 139: declaration of 'enum E14' will not be visible outside of this function File declarators.c Line 145: ISO C forbids forward references to 'enum' types File declarators.c Line 145: declaration of 'enum E15' will not be visible outside of this function ... After: declarators.c:103:24: error: expected ';' at end of declaration void knrNoSemi(i) int i { } ^ ; Patch found in a sealed envelope dated 1978 with the message "Do not open until January 2014" llvm-svn: 198540
2014-01-05 11:27:57 +08:00
void knrNoSemi(i) int i { } // expected-error {{expected ';' at end of declaration}}
// PR12595
void test18() {
int x = 4+(5-12)); // expected-error {{extraneous ')' before ';'}}
}
enum E1 { e1 }: // expected-error {{expected ';'}}
struct EnumBitfield { // expected-warning {{struct without named members is a GNU extension}}
enum E2 { e2 } : 4; // ok
struct S { int n; }: // expected-error {{expected ';'}}
};
// PR10982
enum E11 {
A1 = 1,
};
enum E12 {
, // expected-error{{expected identifier}}
A2
};
void func_E12(enum E12 *p) { *p = A2; }
enum E13 {
1D, // expected-error{{expected identifier}}
A3
};
void func_E13(enum E13 *p) { *p = A3; }
enum E14 {
A4 12, // expected-error{{expected '= constant-expression' or end of enumerator definition}}
A4a
};
void func_E14(enum E14 *p) { *p = A4a; }
enum E15 {
A5=12 4, // expected-error{{expected '}' or ','}}
A5a
};
void func_E15(enum E15 *p) { *p = A5a; }
enum E16 {
A6; // expected-error{{expected '= constant-expression' or end of enumerator definition}}
A6a
};