xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/knr-def-call.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Wconversion -Wliteral-conversion -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // C DR #316, PR 3626.
f0(a,b,c,d)4*f4a2713aSLionel Sambuc void f0(a, b, c, d) int a,b,c,d; {}
t0(void)5*f4a2713aSLionel Sambuc void t0(void) {
6*f4a2713aSLionel Sambuc   f0(1);  // expected-warning{{too few arguments}}
7*f4a2713aSLionel Sambuc }
8*f4a2713aSLionel Sambuc 
f1(a,b)9*f4a2713aSLionel Sambuc void f1(a, b) int a, b; {}
t1(void)10*f4a2713aSLionel Sambuc void t1(void) {
11*f4a2713aSLionel Sambuc   f1(1, 2, 3); // expected-warning{{too many arguments}}
12*f4a2713aSLionel Sambuc }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc void f2(float); // expected-note{{previous declaration is here}}
f2(x)15*f4a2713aSLionel Sambuc 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*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc typedef void (*f3)(void);
t3(int b)18*f4a2713aSLionel Sambuc f3 t3(int b) { return b? f0 : f1; } // okay
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc // <rdar://problem/8193107>
f4()21*f4a2713aSLionel Sambuc void f4() {
22*f4a2713aSLionel Sambuc     char *rindex();
23*f4a2713aSLionel Sambuc }
24*f4a2713aSLionel Sambuc 
rindex(s,c)25*f4a2713aSLionel Sambuc char *rindex(s, c)
26*f4a2713aSLionel Sambuc      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*f4a2713aSLionel Sambuc {
28*f4a2713aSLionel Sambuc   return 0;
29*f4a2713aSLionel Sambuc }
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc // PR8314
32*f4a2713aSLionel Sambuc void proto(int);
proto(x)33*f4a2713aSLionel Sambuc void proto(x)
34*f4a2713aSLionel Sambuc      int x;
35*f4a2713aSLionel Sambuc {
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
use_proto()38*f4a2713aSLionel Sambuc void use_proto() {
39*f4a2713aSLionel Sambuc   proto(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}}
40*f4a2713aSLionel Sambuc   (&proto)(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}}
41*f4a2713aSLionel Sambuc }
42