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