xref: /aosp_15_r20/external/clang/test/Sema/knr-def-call.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -Wconversion -Wliteral-conversion -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // C DR #316, PR 3626.
f0(a,b,c,d)4*67e74705SXin Li void f0(a, b, c, d) int a,b,c,d; {}
t0(void)5*67e74705SXin Li void t0(void) {
6*67e74705SXin Li   f0(1);  // expected-warning{{too few arguments}}
7*67e74705SXin Li }
8*67e74705SXin Li 
f1(a,b)9*67e74705SXin Li void f1(a, b) int a, b; {}
t1(void)10*67e74705SXin Li void t1(void) {
11*67e74705SXin Li   f1(1, 2, 3); // expected-warning{{too many arguments}}
12*67e74705SXin Li }
13*67e74705SXin Li 
14*67e74705SXin Li void f2(float); // expected-note{{previous declaration is here}}
f2(x)15*67e74705SXin Li void f2(x) float x; { } // expected-warning{{promoted type 'double' of K&R function parameter is not compatible with the parameter type 'float' declared in a previous prototype}}
16*67e74705SXin Li 
17*67e74705SXin Li typedef void (*f3)(void);
t3(int b)18*67e74705SXin Li f3 t3(int b) { return b? f0 : f1; } // okay
19*67e74705SXin Li 
20*67e74705SXin Li // <rdar://problem/8193107>
f4()21*67e74705SXin Li void f4() {
22*67e74705SXin Li     char *rindex();
23*67e74705SXin Li }
24*67e74705SXin Li 
rindex(s,c)25*67e74705SXin Li char *rindex(s, c)
26*67e74705SXin Li      register char *s, c; // expected-warning{{promoted type 'char *' of K&R function parameter is not compatible with the parameter type 'const char *' declared in a previous prototype}}
27*67e74705SXin Li {
28*67e74705SXin Li   return 0;
29*67e74705SXin Li }
30*67e74705SXin Li 
31*67e74705SXin Li // PR8314
32*67e74705SXin Li void proto(int);
proto(x)33*67e74705SXin Li void proto(x)
34*67e74705SXin Li      int x;
35*67e74705SXin Li {
36*67e74705SXin Li }
37*67e74705SXin Li 
use_proto()38*67e74705SXin Li void use_proto() {
39*67e74705SXin Li   proto(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}}
40*67e74705SXin Li   (&proto)(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}}
41*67e74705SXin Li }
42