blob: 26be61416b3cb0632abc8aea80311da07c7cf741 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
Eli Friedman4f64e182011-11-11 02:00:42 +00002
3// PR1892, PR11354
4void f(double a[restrict][5]) { __typeof(a) x = 10; } // expected-warning {{(aka 'double (*restrict)[5]')}}
Chris Lattner4f203512008-01-02 22:50:48 +00005
Steve Narofff06b5ba2008-01-29 00:15:50 +00006int foo (__const char *__path);
7int foo(__const char *__restrict __file);
8
Chris Lattner0369c572008-11-23 23:12:31 +00009void func(const char*); // expected-note {{previous declaration is here}}
10void func(char*); // expected-error{{conflicting types for 'func'}}
Steve Naroffddb1dd82008-01-29 18:58:14 +000011
Chris Lattnerfd652912008-01-14 05:45:46 +000012void g(int (*)(const void **, const void **));
13void g(int (*compar)()) {
14}
15
Chris Lattner0369c572008-11-23 23:12:31 +000016void h(); // expected-note {{previous declaration is here}}
17void h (const char *fmt, ...) {} // expected-error{{conflicting types for 'h'}}
Chris Lattner4973fb92008-01-31 06:06:29 +000018
19// PR1965
20int t5(b); // expected-error {{parameter list without types}}
Chris Lattner9d51f2b2008-04-05 06:32:51 +000021int t6(int x, g); // expected-warning {{type specifier missing, defaults to 'int'}}
Chris Lattner4973fb92008-01-31 06:06:29 +000022
Chris Lattner7b8134f2008-02-10 23:08:00 +000023int t7(, ); // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
24int t8(, int a); // expected-error {{expected parameter declarator}}
25int t9(int a, ); // expected-error {{expected parameter declarator}}
Chris Lattner4973fb92008-01-31 06:06:29 +000026
27
Chris Lattnerb080ed52008-02-17 19:31:09 +000028// PR2042
29void t10(){}
Douglas Gregord8e97de2009-04-02 15:37:10 +000030void t11(){t10(1);} // expected-warning{{too many arguments}}
Chris Lattnerb080ed52008-02-17 19:31:09 +000031
Chris Lattner3d722972008-12-17 07:32:46 +000032// PR3208
33void t12(int) {} // expected-error{{parameter name omitted}}
34
Chris Lattner27e5bef2008-12-18 02:01:17 +000035// PR2790
36void t13() {
Chris Lattner33919e72010-07-11 23:34:02 +000037 return 0; // expected-error {{void function 't13' should not return a value}}
Chris Lattner27e5bef2008-12-18 02:01:17 +000038}
39int t14() {
Chris Lattner33919e72010-07-11 23:34:02 +000040 return; // expected-error {{non-void function 't14' should return a value}}
Chris Lattner27e5bef2008-12-18 02:01:17 +000041}
Douglas Gregor9aa89042009-01-23 16:23:13 +000042
43// <rdar://problem/6097326>
44y(y) { return y; } // expected-warning{{parameter 'y' was not declared, defaulting to type 'int'}} \
45 // expected-warning{{type specifier missing, defaults to 'int'}}
Eli Friedmancddff7f2009-02-04 18:50:00 +000046
47
Douglas Gregor4ab311d2009-02-04 19:10:27 +000048// PR3137, <rdar://problem/6127293>
Eli Friedmancddff7f2009-02-04 18:50:00 +000049extern int g0_3137(void);
50void f0_3137() {
51 int g0_3137(void);
52}
53void f1_3137() {
54 int (*fp)(void) = g0_3137;
55}
Douglas Gregore62c0a42009-02-24 01:23:02 +000056
57void f1static() {
58 static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}}
59 register void f2register(int); // expected-error{{illegal storage class on function}}
60}
Eli Friedman9ad72442009-03-04 07:30:59 +000061
Douglas Gregorac1fb652009-03-24 19:52:54 +000062struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
63 // expected-note{{forward declaration of 'struct incomplete_test'}}
Chris Lattner4225e232009-04-14 17:02:11 +000064
65
66extern __inline
Eli Friedman2b680b42009-04-28 03:13:54 +000067__attribute__((__gnu_inline__))
Chris Lattner4225e232009-04-14 17:02:11 +000068void gnu_inline1() {}
69
70void
Eli Friedman2b680b42009-04-28 03:13:54 +000071__attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
Chris Lattner4225e232009-04-14 17:02:11 +000072gnu_inline2() {}
Chris Lattnerfbbf5392009-04-17 19:32:54 +000073
74
75// rdar://6802350
76inline foo_t invalid_type() { // expected-error {{unknown type name 'foo_t'}}
77}
78
Chris Lattnerae4ee5b2009-04-25 05:51:56 +000079typedef void fn_t(void);
80fn_t t17;
81
Chris Lattner9af40c12009-04-25 06:12:16 +000082// PR4049
Chris Lattneredfa8d42009-04-25 08:47:54 +000083unknown_type t18(void*) { // expected-error {{unknown type name 'unknown_type'}} expected-error{{parameter name omitted}}
84}
85
86unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type'}}
87 P = P+1; // no warning.
Chris Lattner9af40c12009-04-25 06:12:16 +000088}
Chris Lattnerfbbf5392009-04-17 19:32:54 +000089
Douglas Gregor9bfc2e52009-09-22 21:41:40 +000090// missing ',' before '...'
91void t20(int i...) { } // expected-error {{requires a comma}}
Douglas Gregor81bd0382012-01-13 23:06:53 +000092
93int n;
94void t21(int n, int (*array)[n]);
Douglas Gregor012efe22013-04-16 16:01:32 +000095
96int func_e(int x) {
97 int func_n(int y) { // expected-error {{function definition is not allowed here}}
98 if (y > 22) {
99 return y+2;
100 } else {
101 return y-2;
102 }
103 }
104 return x + 3;
105}
Reid Kleckner8a365022013-06-24 17:51:48 +0000106
107void decays(int a[3][3]); // expected-note {{passing argument to parameter 'a' here}}
108void no_decay(int (*a)[3]); // expected-note {{passing argument to parameter 'a' here}}
109
110void t22(int *ptr, int (*array)[3]) {
111 decays(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
112 no_decay(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
113 decays(array);
114 no_decay(array);
115}
Nathan Sidwellc1168022015-01-15 16:45:53 +0000116
117void const Bar (void); // ok on decl
118// PR 20146
Nathan Sidwell0ba19402015-01-28 14:48:39 +0000119void const Bar (void) // expected-warning {{function cannot return qualified void type 'const void'}}
Nathan Sidwellc1168022015-01-15 16:45:53 +0000120{
121}