blob: fb69fa9c1d05a71223eb0435ede09833e9f949cf [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
Chris Lattnerdf89dd42006-08-06 18:22:00 +00002
Chris Lattner7cf04d12007-06-08 18:15:09 +00003extern int a1[];
Chris Lattnerdf89dd42006-08-06 18:22:00 +00004
5void f0();
6void f1(int [*]);
7void f2(int [const *]);
8void f3(int [volatile const*]);
Chris Lattner9d51f2b2008-04-05 06:32:51 +00009int f4(*XX)(void); /* expected-error {{cannot return}} expected-warning {{type specifier missing, defaults to 'int'}} */
Chris Lattnerdf89dd42006-08-06 18:22:00 +000010
11char ((((*X))));
12
13void (*signal(int, void (*)(int)))(int);
14
Chris Lattner67b0d6a2009-04-12 22:12:26 +000015int aaaa, ***C, * const D, B(int);
Chris Lattnerdf89dd42006-08-06 18:22:00 +000016
17int *A;
18
Chris Lattner7bddb3f2006-08-13 19:59:13 +000019struct str;
20
Mike Stump753d1202009-07-22 00:43:08 +000021void test2(int *P, int A) {
Chris Lattner7bddb3f2006-08-13 19:59:13 +000022 struct str;
23
24 // Hard case for array decl, not Array[*].
Chris Lattner3b51ddf2006-08-12 18:40:31 +000025 int Array[*(int*)P+A];
26}
Chris Lattner7bddb3f2006-08-13 19:59:13 +000027
Chris Lattner67b450c2008-04-06 06:47:48 +000028typedef int atype;
Mike Stump753d1202009-07-22 00:43:08 +000029void test3(x,
30 atype /* expected-error {{unexpected type name 'atype': expected identifier}} */
31 ) int x, atype; {}
Chris Lattner7bddb3f2006-08-13 19:59:13 +000032
Mike Stump753d1202009-07-22 00:43:08 +000033void test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */
Chris Lattner285a3e42008-04-06 06:50:56 +000034
Chris Lattner8c5dd732008-11-11 06:13:16 +000035
36// PR3031
37int (test5), ; // expected-error {{expected identifier or '('}}
38
Chris Lattner6cc055a2009-04-12 20:42:31 +000039
40
41// PR3963 & rdar://6759604 - test error recovery for mistyped "typenames".
42
Chris Lattner6cc055a2009-04-12 20:42:31 +000043foo_t *d; // expected-error {{unknown type name 'foo_t'}}
Chris Lattner67b0d6a2009-04-12 22:12:26 +000044foo_t a; // expected-error {{unknown type name 'foo_t'}}
Chris Lattnerffaa0e62009-04-12 21:49:30 +000045int test6() { return a; } // a should be declared.
Chris Lattner6cc055a2009-04-12 20:42:31 +000046
Chris Lattnerffaa0e62009-04-12 21:49:30 +000047// Use of tagged type without tag. rdar://6783347
48struct xyz { int y; };
49enum myenum { ASDFAS };
John McCall38200b02010-02-14 01:03:10 +000050xyz 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'}}
Chris Lattnerffaa0e62009-04-12 21:49:30 +000052
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.
Douglas Gregorc68e1402010-04-09 00:35:39 +000056 return &b.y; // expected-warning {{incompatible pointer types returning 'int *' from a function with result type 'float *'}}
Chris Lattnerffaa0e62009-04-12 21:49:30 +000057}
58
Chris Lattner67b0d6a2009-04-12 22:12:26 +000059struct xyz test8() { return a; } // a should be be marked invalid, no diag.
60
Chris Lattnerffaa0e62009-04-12 21:49:30 +000061
62// Verify that implicit int still works.
Chris Lattner6cc055a2009-04-12 20:42:31 +000063static 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'}}
Eli Friedman2b680b42009-04-28 03:13:54 +000066 __asm__("foo");
Chris Lattner245c5332010-02-02 00:37:27 +000067
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};
Chris Lattnerafe6a842010-02-02 17:32:27 +000074
75// PR6208
76struct test10 { int a; } static test10x;
77struct test11 { int a; } const test11x;
Chris Lattner35af0ab2010-02-03 01:45:03 +000078
79// PR6216
80void test12() {
81 (void)__builtin_offsetof(struct { char c; int i; }, i);
82}
Chris Lattner5e854b92010-02-03 20:41:24 +000083
84// rdar://7608537
85struct test13 { int a; } (test13x);
Douglas Gregord5a479c2010-05-30 22:30:21 +000086
87// <rdar://problem/8044088>
88struct X<foo::int> { }; // expected-error{{expected identifier or '('}}
Chris Lattner13901342010-07-11 22:42:07 +000089
90
91// PR7617 - error recovery on missing ;.
92
Chris Lattneref74e2b22010-07-11 22:46:04 +000093void test14() // expected-error {{expected ';' after top level declarator}}
Chris Lattner13901342010-07-11 22:42:07 +000094
95void test14a();
96void *test14b = (void*)test14a; // Make sure test14a didn't get skipped.