Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- validation/cast-bad-00.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 validation/cast-bad-00.c diff --git a/validation/cast-bad-00.c b/validation/cast-bad-00.c new file mode 100644 index 000000000..5f4a895f5 --- /dev/null +++ b/validation/cast-bad-00.c @@ -0,0 +1,47 @@ +typedef unsigned short u16; +typedef unsigned int u32; + +union u { + u32 a; + u16 b; +}; + +struct s { + u32 a; + u16 b; +}; + + +void bar(u16, u32); +void union_to_int(u16 val); +void struct_to_int(u16 val); + + +void union_to_int(u16 val) +{ + union u u; + + u.b = val; + bar(u.b, u); +} + +void struct_to_int(u16 val) +{ + struct s s; + + s.b = val; + bar(s.b, s); +} + +/* + * check-name: cast-bad 00 + * + * check-error-start +cast-bad-00.c:25:18: warning: incorrect type in argument 2 (different base types) +cast-bad-00.c:25:18: expected unsigned int [unsigned] [usertype] <noident> +cast-bad-00.c:25:18: got union u [assigned] u +cast-bad-00.c:33:18: warning: incorrect type in argument 2 (different base types) +cast-bad-00.c:33:18: expected unsigned int [unsigned] [usertype] <noident> +cast-bad-00.c:33:18: got struct s [assigned] s + * check-error-end + */ -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html