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