1 /* Test diagnostics for bad implicit type conversions. */
2 /* Origin: Joseph Myers <jsm@polyomino.org.uk> */
3 /* { dg-do compile } */
4 /* { dg-options "-pedantic" } */
6 #define TESTARG(ID, TL, TR) void ID##F(TL); void ID##F2(TR x) { ID##F(x); } extern int dummy
7 #define TESTARP(ID, TL, TR) struct { void (*x)(TL); } ID##Fp; void ID##F2(TR x) { ID##Fp.x(x); } extern int dummy
8 #define TESTASS(ID, TL, TR) void ID##F(TR x) { TL y; y = x; } extern int dummy
9 #define TESTINI(ID, TL, TR) void ID##F(TR x) { TL y = x; } extern int dummy
10 #define TESTRET(ID, TL, TR) TR ID##V; TL ID##F(void) { return ID##V; } extern int dummy
12 typedef void (*fp
)(void);
13 typedef void (*nrfp
)(void) __attribute__((noreturn
));
15 TESTARG(fqa
, nrfp
, fp
); /* { dg-warning "passing argument 1 of 'fqaF' makes qualified function pointer from unqualified" } */
16 TESTARP(fqb
, nrfp
, fp
); /* { dg-warning "passing argument 1 of 'fqbFp.x' makes qualified function pointer from unqualified" } */
17 TESTASS(fqc
, nrfp
, fp
); /* { dg-warning "assignment makes qualified function pointer from unqualified" } */
18 TESTINI(fqd
, nrfp
, fp
); /* { dg-warning "initialization makes qualified function pointer from unqualified" } */
19 TESTRET(fqe
, nrfp
, fp
); /* { dg-warning "return makes qualified function pointer from unqualified" } */
21 TESTARG(ofqa
, fp
, nrfp
);
22 TESTARP(ofqb
, fp
, nrfp
);
23 TESTASS(ofqc
, fp
, nrfp
);
24 TESTINI(ofqd
, fp
, nrfp
);
25 TESTRET(ofqe
, fp
, nrfp
);
27 TESTARG(qa
, char *, const char *); /* { dg-warning "passing argument 1 of 'qaF' discards qualifiers from pointer target type" } */
28 TESTARP(qb
, char *, const char *); /* { dg-warning "passing argument 1 of 'qbFp.x' discards qualifiers from pointer target type" } */
29 TESTASS(qc
, char *, const char *); /* { dg-warning "assignment discards qualifiers from pointer target type" } */
30 TESTINI(qd
, char *, const char *); /* { dg-warning "initialization discards qualifiers from pointer target type" } */
31 TESTRET(qe
, char *, const char *); /* { dg-warning "return discards qualifiers from pointer target type" } */
33 TESTARG(oqa
, const char *, char *);
34 TESTARP(oqb
, const char *, char *);
35 TESTASS(oqc
, const char *, char *);
36 TESTINI(oqd
, const char *, char *);
37 TESTRET(oqe
, const char *, char *);
39 TESTARG(fda
, fp
, void *); /* { dg-warning "ISO C forbids passing argument 1 of 'fdaF' between function pointer and 'void \\*'" } */
40 TESTARP(fdb
, fp
, void *); /* { dg-warning "ISO C forbids passing argument 1 of 'fdbFp.x' between function pointer and 'void \\*'" } */
41 TESTASS(fdc
, fp
, void *); /* { dg-warning "ISO C forbids assignment between function pointer and 'void \\*'" } */
42 TESTINI(fdd
, fp
, void *); /* { dg-warning "ISO C forbids initialization between function pointer and 'void \\*'" } */
43 TESTRET(fde
, fp
, void *); /* { dg-warning "ISO C forbids return between function pointer and 'void \\*'" } */
45 TESTARG(dfa
, void *, fp
); /* { dg-warning "ISO C forbids passing argument 1 of 'dfaF' between function pointer and 'void \\*'" } */
46 TESTARP(dfb
, void *, fp
); /* { dg-warning "ISO C forbids passing argument 1 of 'dfbFp.x' between function pointer and 'void \\*'" } */
47 TESTASS(dfc
, void *, fp
); /* { dg-warning "ISO C forbids assignment between function pointer and 'void \\*'" } */
48 TESTINI(dfd
, void *, fp
); /* { dg-warning "ISO C forbids initialization between function pointer and 'void \\*'" } */
49 TESTRET(dfe
, void *, fp
); /* { dg-warning "ISO C forbids return between function pointer and 'void \\*'" } */
51 TESTARG(sua
, int *, unsigned int *); /* { dg-warning "pointer targets in passing argument 1 of 'suaF' differ in signedness" } */
52 TESTARP(sub
, int *, unsigned int *); /* { dg-warning "pointer targets in passing argument 1 of 'subFp.x' differ in signedness" } */
53 TESTASS(suc
, int *, unsigned int *); /* { dg-warning "pointer targets in assignment differ in signedness" } */
54 TESTINI(sud
, int *, unsigned int *); /* { dg-warning "pointer targets in initialization differ in signedness" } */
55 TESTRET(sue
, int *, unsigned int *); /* { dg-warning "pointer targets in return differ in signedness" } */
57 TESTARG(usa
, unsigned int *, int *); /* { dg-warning "pointer targets in passing argument 1 of 'usaF' differ in signedness" } */
58 TESTARP(usb
, unsigned int *, int *); /* { dg-warning "pointer targets in passing argument 1 of 'usbFp.x' differ in signedness" } */
59 TESTASS(usc
, unsigned int *, int *); /* { dg-warning "pointer targets in assignment differ in signedness" } */
60 TESTINI(usd
, unsigned int *, int *); /* { dg-warning "pointer targets in initialization differ in signedness" } */
61 TESTRET(use
, unsigned int *, int *); /* { dg-warning "pointer targets in return differ in signedness" } */
63 TESTARG(cua
, char *, unsigned char *); /* { dg-warning "pointer targets in passing argument 1 of 'cuaF' differ in signedness" } */
64 TESTARP(cub
, char *, unsigned char *); /* { dg-warning "pointer targets in passing argument 1 of 'cubFp.x' differ in signedness" } */
65 TESTASS(cuc
, char *, unsigned char *); /* { dg-warning "pointer targets in assignment differ in signedness" } */
66 TESTINI(cud
, char *, unsigned char *); /* { dg-warning "pointer targets in initialization differ in signedness" } */
67 TESTRET(cue
, char *, unsigned char *); /* { dg-warning "pointer targets in return differ in signedness" } */
69 TESTARG(uca
, unsigned char *, char *); /* { dg-warning "pointer targets in passing argument 1 of 'ucaF' differ in signedness" } */
70 TESTARP(ucb
, unsigned char *, char *); /* { dg-warning "pointer targets in passing argument 1 of 'ucbFp.x' differ in signedness" } */
71 TESTASS(ucc
, unsigned char *, char *); /* { dg-warning "pointer targets in assignment differ in signedness" } */
72 TESTINI(ucd
, unsigned char *, char *); /* { dg-warning "pointer targets in initialization differ in signedness" } */
73 TESTRET(uce
, unsigned char *, char *); /* { dg-warning "pointer targets in return differ in signedness" } */
75 TESTARG(csa
, char *, signed char *); /* { dg-warning "pointer targets in passing argument 1 of 'csaF' differ in signedness" } */
76 TESTARP(csb
, char *, signed char *); /* { dg-warning "pointer targets in passing argument 1 of 'csbFp.x' differ in signedness" } */
77 TESTASS(csc
, char *, signed char *); /* { dg-warning "pointer targets in assignment differ in signedness" } */
78 TESTINI(csd
, char *, signed char *); /* { dg-warning "pointer targets in initialization differ in signedness" } */
79 TESTRET(cse
, char *, signed char *); /* { dg-warning "pointer targets in return differ in signedness" } */
81 TESTARG(sca
, signed char *, char *); /* { dg-warning "pointer targets in passing argument 1 of 'scaF' differ in signedness" } */
82 TESTARP(scb
, signed char *, char *); /* { dg-warning "pointer targets in passing argument 1 of 'scbFp.x' differ in signedness" } */
83 TESTASS(scc
, signed char *, char *); /* { dg-warning "pointer targets in assignment differ in signedness" } */
84 TESTINI(scd
, signed char *, char *); /* { dg-warning "pointer targets in initialization differ in signedness" } */
85 TESTRET(sce
, signed char *, char *); /* { dg-warning "pointer targets in return differ in signedness" } */
87 TESTARG(cia
, char *, int *); /* { dg-warning "passing argument 1 of 'ciaF' from incompatible pointer type" } */
88 TESTARP(cib
, char *, int *); /* { dg-warning "passing argument 1 of 'cibFp.x' from incompatible pointer type" } */
89 TESTASS(cic
, char *, int *); /* { dg-warning "assignment from incompatible pointer type" } */
90 TESTINI(cid
, char *, int *); /* { dg-warning "initialization from incompatible pointer type" } */
91 TESTRET(cie
, char *, int *); /* { dg-warning "return from incompatible pointer type" } */
93 TESTARG(ica
, int *, char *); /* { dg-warning "passing argument 1 of 'icaF' from incompatible pointer type" } */
94 TESTARP(icb
, int *, char *); /* { dg-warning "passing argument 1 of 'icbFp.x' from incompatible pointer type" } */
95 TESTASS(icc
, int *, char *); /* { dg-warning "assignment from incompatible pointer type" } */
96 TESTINI(icd
, int *, char *); /* { dg-warning "initialization from incompatible pointer type" } */
97 TESTRET(ice
, int *, char *); /* { dg-warning "return from incompatible pointer type" } */
99 TESTARG(ciia
, char *, int); /* { dg-warning "passing argument 1 of 'ciiaF' makes pointer from integer without a cast" } */
100 TESTARP(ciib
, char *, int); /* { dg-warning "passing argument 1 of 'ciibFp.x' makes pointer from integer without a cast" } */
101 TESTASS(ciic
, char *, int); /* { dg-warning "assignment makes pointer from integer without a cast" } */
102 TESTINI(ciid
, char *, int); /* { dg-warning "initialization makes pointer from integer without a cast" } */
103 TESTRET(ciie
, char *, int); /* { dg-warning "return makes pointer from integer without a cast" } */
105 TESTARG(iica
, int, char *); /* { dg-warning "passing argument 1 of 'iicaF' makes integer from pointer without a cast" } */
106 TESTARP(iicb
, int, char *); /* { dg-warning "passing argument 1 of 'iicbFp.x' makes integer from pointer without a cast" } */
107 TESTASS(iicc
, int, char *); /* { dg-warning "assignment makes integer from pointer without a cast" } */
108 TESTINI(iicd
, int, char *); /* { dg-warning "initialization makes integer from pointer without a cast" } */
109 TESTRET(iice
, int, char *); /* { dg-warning "return makes integer from pointer without a cast" } */
113 TESTARG(stria
, struct s
, int); /* { dg-error "incompatible type for argument 1 of 'striaF'" } */
114 TESTARP(strib
, struct s
, int); /* { dg-error "incompatible type for argument 1 of 'stribFp.x'" } */
115 TESTASS(stric
, struct s
, int); /* { dg-error "incompatible types in assignment" } */
116 TESTINI(strid
, struct s
, int); /* { dg-error "invalid initializer" } */
117 TESTRET(strie
, struct s
, int); /* { dg-error "incompatible types in return" } */
119 TESTARG(istra
, int, struct s
); /* { dg-error "incompatible type for argument 1 of 'istraF'" } */
120 TESTARP(istrb
, int, struct s
); /* { dg-error "incompatible type for argument 1 of 'istrbFp.x'" } */
121 TESTASS(istrc
, int, struct s
); /* { dg-error "incompatible types in assignment" } */
122 TESTINI(istrd
, int, struct s
); /* { dg-error "incompatible types in initialization" } */
123 TESTRET(istre
, int, struct s
); /* { dg-error "incompatible types in return" } */
125 /* Match all extra informative notes. */
126 /* { dg-message "note: expected '\[^\n'\]*' but argument is of type '\[^\n'\]*'" "note: expected" { target *-*-* } 0 } */