xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/function.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // PR1892, PR11354
f(double a[restrict][5])4*f4a2713aSLionel Sambuc void f(double a[restrict][5]) { __typeof(a) x = 10; } // expected-warning {{(aka 'double (*restrict)[5]')}}
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc int foo (__const char *__path);
7*f4a2713aSLionel Sambuc int foo(__const char *__restrict __file);
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc void func(const char*); // expected-note {{previous declaration is here}}
10*f4a2713aSLionel Sambuc void func(char*); // expected-error{{conflicting types for 'func'}}
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc void g(int (*)(const void **, const void **));
g(int (* compar)())13*f4a2713aSLionel Sambuc void g(int (*compar)()) {
14*f4a2713aSLionel Sambuc }
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc void h();  // expected-note {{previous declaration is here}}
h(const char * fmt,...)17*f4a2713aSLionel Sambuc void h (const char *fmt, ...) {} // expected-error{{conflicting types for 'h'}}
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc // PR1965
20*f4a2713aSLionel Sambuc int t5(b);          // expected-error {{parameter list without types}}
21*f4a2713aSLionel Sambuc int t6(int x, g);   // expected-warning {{type specifier missing, defaults to 'int'}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc int t7(, );       // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
24*f4a2713aSLionel Sambuc int t8(, int a);  // expected-error {{expected parameter declarator}}
25*f4a2713aSLionel Sambuc int t9(int a, );  // expected-error {{expected parameter declarator}}
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc // PR2042
t10()29*f4a2713aSLionel Sambuc void t10(){}
t11()30*f4a2713aSLionel Sambuc void t11(){t10(1);} // expected-warning{{too many arguments}}
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc // PR3208
t12(int)33*f4a2713aSLionel Sambuc void t12(int) {}  // expected-error{{parameter name omitted}}
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc // PR2790
t13()36*f4a2713aSLionel Sambuc void t13() {
37*f4a2713aSLionel Sambuc   return 0; // expected-error {{void function 't13' should not return a value}}
38*f4a2713aSLionel Sambuc }
t14()39*f4a2713aSLionel Sambuc int t14() {
40*f4a2713aSLionel Sambuc   return; // expected-error {{non-void function 't14' should return a value}}
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc // <rdar://problem/6097326>
y(y)44*f4a2713aSLionel Sambuc y(y) { return y; } // expected-warning{{parameter 'y' was not declared, defaulting to type 'int'}} \
45*f4a2713aSLionel Sambuc                    // expected-warning{{type specifier missing, defaults to 'int'}}
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc // PR3137, <rdar://problem/6127293>
49*f4a2713aSLionel Sambuc extern int g0_3137(void);
f0_3137()50*f4a2713aSLionel Sambuc void f0_3137() {
51*f4a2713aSLionel Sambuc   int g0_3137(void);
52*f4a2713aSLionel Sambuc }
f1_3137()53*f4a2713aSLionel Sambuc void f1_3137() {
54*f4a2713aSLionel Sambuc   int (*fp)(void) = g0_3137;
55*f4a2713aSLionel Sambuc }
56*f4a2713aSLionel Sambuc 
f1static()57*f4a2713aSLionel Sambuc void f1static() {
58*f4a2713aSLionel Sambuc   static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}}
59*f4a2713aSLionel Sambuc   register void f2register(int); // expected-error{{illegal storage class on function}}
60*f4a2713aSLionel Sambuc }
61*f4a2713aSLionel Sambuc 
a(void)62*f4a2713aSLionel Sambuc struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
63*f4a2713aSLionel Sambuc     // expected-note{{forward declaration of 'struct incomplete_test'}}
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc extern __inline
67*f4a2713aSLionel Sambuc __attribute__((__gnu_inline__))
gnu_inline1()68*f4a2713aSLionel Sambuc void gnu_inline1() {}
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc void
71*f4a2713aSLionel Sambuc __attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
gnu_inline2()72*f4a2713aSLionel Sambuc gnu_inline2() {}
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc // rdar://6802350
invalid_type()76*f4a2713aSLionel Sambuc inline foo_t invalid_type() {  // expected-error {{unknown type name 'foo_t'}}
77*f4a2713aSLionel Sambuc }
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc typedef void fn_t(void);
80*f4a2713aSLionel Sambuc fn_t t17;
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc // PR4049
t18(void *)83*f4a2713aSLionel Sambuc unknown_type t18(void*) {   // expected-error {{unknown type name 'unknown_type'}} expected-error{{parameter name omitted}}
84*f4a2713aSLionel Sambuc }
85*f4a2713aSLionel Sambuc 
t19(int * P)86*f4a2713aSLionel Sambuc unknown_type t19(int* P) {   // expected-error {{unknown type name 'unknown_type'}}
87*f4a2713aSLionel Sambuc   P = P+1;  // no warning.
88*f4a2713aSLionel Sambuc }
89*f4a2713aSLionel Sambuc 
90*f4a2713aSLionel Sambuc // missing ',' before '...'
t20(int i...)91*f4a2713aSLionel Sambuc void t20(int i...) { } // expected-error {{requires a comma}}
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc int n;
94*f4a2713aSLionel Sambuc void t21(int n, int (*array)[n]);
95*f4a2713aSLionel Sambuc 
func_e(int x)96*f4a2713aSLionel Sambuc int func_e(int x) {
97*f4a2713aSLionel Sambuc   int func_n(int y) { // expected-error {{function definition is not allowed here}}
98*f4a2713aSLionel Sambuc     if (y > 22) {
99*f4a2713aSLionel Sambuc       return y+2;
100*f4a2713aSLionel Sambuc     } else {
101*f4a2713aSLionel Sambuc       return y-2;
102*f4a2713aSLionel Sambuc     }
103*f4a2713aSLionel Sambuc   }
104*f4a2713aSLionel Sambuc   return x + 3;
105*f4a2713aSLionel Sambuc }
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc void decays(int a[3][3]);   // expected-note {{passing argument to parameter 'a' here}}
108*f4a2713aSLionel Sambuc void no_decay(int (*a)[3]); // expected-note {{passing argument to parameter 'a' here}}
109*f4a2713aSLionel Sambuc 
t22(int * ptr,int (* array)[3])110*f4a2713aSLionel Sambuc void t22(int *ptr, int (*array)[3]) {
111*f4a2713aSLionel Sambuc   decays(ptr);   // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
112*f4a2713aSLionel Sambuc   no_decay(ptr); // expected-warning {{incompatible pointer types passing 'int *' to parameter of type 'int (*)[3]'}}
113*f4a2713aSLionel Sambuc   decays(array);
114*f4a2713aSLionel Sambuc   no_decay(array);
115*f4a2713aSLionel Sambuc }
116