2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
|
2006-08-07 02:22:00 +08:00
|
|
|
|
2007-06-09 02:15:09 +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*]);
|
2008-04-05 14:32:51 +08:00
|
|
|
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);
|
|
|
|
|
2009-04-13 06:12:26 +08:00
|
|
|
int aaaa, ***C, * const D, B(int);
|
2006-08-07 02:22:00 +08:00
|
|
|
|
|
|
|
int *A;
|
|
|
|
|
2006-08-14 03:59:13 +08:00
|
|
|
struct str;
|
|
|
|
|
2009-07-22 08:43:08 +08:00
|
|
|
void test2(int *P, int A) {
|
2006-08-14 03:59:13 +08:00
|
|
|
struct str;
|
|
|
|
|
|
|
|
// Hard case for array decl, not Array[*].
|
2006-08-13 02:40:31 +08:00
|
|
|
int Array[*(int*)P+A];
|
|
|
|
}
|
2006-08-14 03:59:13 +08:00
|
|
|
|
2008-04-06 14:47:48 +08:00
|
|
|
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; {}
|
2006-08-14 03:59:13 +08:00
|
|
|
|
2009-07-22 08:43:08 +08:00
|
|
|
void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */
|
2008-04-06 14:50:56 +08:00
|
|
|
|
2008-11-11 14:13:16 +08:00
|
|
|
|
|
|
|
// PR3031
|
|
|
|
int (test5), ; // expected-error {{expected identifier or '('}}
|
|
|
|
|
2009-04-13 04:42:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR3963 & rdar://6759604 - test error recovery for mistyped "typenames".
|
|
|
|
|
2009-04-13 05:49:30 +08:00
|
|
|
foo_t *d; // expected-error {{unknown type name 'foo_t'}}
|
2009-04-13 06:12:26 +08:00
|
|
|
foo_t a; // expected-error {{unknown type name 'foo_t'}}
|
2009-04-13 05:49:30 +08:00
|
|
|
int test6() { return a; } // a should be declared.
|
|
|
|
|
|
|
|
// Use of tagged type without tag. rdar://6783347
|
|
|
|
struct xyz { int y; };
|
|
|
|
enum myenum { ASDFAS };
|
2010-02-14 09:03:10 +08:00
|
|
|
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'}}
|
2009-04-13 05:49:30 +08:00
|
|
|
|
|
|
|
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.
|
2010-04-09 08:35:39 +08:00
|
|
|
return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}}
|
2009-04-13 05:49:30 +08:00
|
|
|
}
|
2009-04-13 04:42:31 +08:00
|
|
|
|
2009-04-13 06:12:26 +08:00
|
|
|
struct xyz test8() { return a; } // a should be be marked invalid, no diag.
|
|
|
|
|
2009-04-13 04:42:31 +08:00
|
|
|
|
2009-04-13 05:49:30 +08:00
|
|
|
// Verify that implicit int still works.
|
2009-04-13 04:42:31 +08:00
|
|
|
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'}}
|
2009-04-28 11:13:54 +08:00
|
|
|
__asm__("foo");
|
2010-02-02 08:37:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct test9 {
|
|
|
|
int x // expected-error {{expected ';' at end of declaration list}}
|
|
|
|
int y;
|
|
|
|
int z // expected-warning {{expected ';' at end of declaration list}}
|
|
|
|
};
|
2010-02-03 01:32:27 +08:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2010-02-04 04:41:24 +08:00
|
|
|
|
|
|
|
// rdar://7608537
|
|
|
|
struct test13 { int a; } (test13x);
|
2010-05-31 06:30:21 +08:00
|
|
|
|
|
|
|
// <rdar://problem/8044088>
|
|
|
|
struct X<foo::int> { }; // expected-error{{expected identifier or '('}}
|
2010-07-12 06:42:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR7617 - error recovery on missing ;.
|
|
|
|
|
2010-07-12 06:46:04 +08:00
|
|
|
void test14() // expected-error {{expected ';' after top level declarator}}
|
2010-07-12 06:42:07 +08:00
|
|
|
|
|
|
|
void test14a();
|
|
|
|
void *test14b = (void*)test14a; // Make sure test14a didn't get skipped.
|
2010-08-27 01:22:34 +08:00
|
|
|
|
|
|
|
// rdar://problem/8358508
|
2010-08-27 01:42:30 +08:00
|
|
|
long struct X { int x; } test15(); // expected-error {{'long struct' is invalid}}
|
2012-04-07 07:33:59 +08:00
|
|
|
|
|
|
|
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}}
|
2014-01-05 11:27:57 +08:00
|
|
|
void knrNoSemi(i) int i { } // expected-error {{expected ';' at end of declaration}}
|
2012-04-29 00:12:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR12595
|
|
|
|
void test18() {
|
|
|
|
int x = 4+(5-12)); // expected-error {{extraneous ')' before ';'}}
|
|
|
|
}
|
|
|
|
|
2012-07-03 03:14:01 +08:00
|
|
|
enum E1 { e1 }: // expected-error {{expected ';'}}
|
2013-06-08 21:29:58 +08:00
|
|
|
struct EnumBitfield { // expected-warning {{struct without named members is a GNU extension}}
|
2012-07-03 03:14:01 +08:00
|
|
|
enum E2 { e2 } : 4; // ok
|
|
|
|
struct S { int n; }: // expected-error {{expected ';'}}
|
2013-06-08 21:29:58 +08:00
|
|
|
|
2012-07-03 03:14:01 +08:00
|
|
|
};
|
2013-12-31 14:26:03 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
|
};
|