aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-11-24 12:30:08 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-06-23 07:46:39 +0200
commit9ab2dd6f368ef2d109b9d89c06d79868e9fbcc8b (patch)
tree798a6bbdef88d1eb39e00e2e3cbcdefe2a06a95c /validation
parent86af2a17d26712bce69759120c290c5ede88f677 (diff)
downloadsparse-dev-9ab2dd6f368ef2d109b9d89c06d79868e9fbcc8b.tar.gz
cast: add testcase for bad implicit casts to struct/union
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/cast-bad-00.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/validation/cast-bad-00.c b/validation/cast-bad-00.c
new file mode 100644
index 00000000..5f4a895f
--- /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
+ */