summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ubsan/pr91993.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/ubsan/pr91993.C')
-rw-r--r--gcc/testsuite/g++.dg/ubsan/pr91993.C17
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/ubsan/pr91993.C b/gcc/testsuite/g++.dg/ubsan/pr91993.C
new file mode 100644
index 00000000000..f903398060a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr91993.C
@@ -0,0 +1,17 @@
+// PR c++/91993
+// { dg-do compile }
+// { dg-options "-Wconversion -fsanitize=undefined" }
+
+typedef unsigned char uc;
+
+int
+foo (const uc &a, const uc &b, const uc &c)
+{
+ return static_cast<uc>(static_cast<uc>(a << 1U) | b) | c; // { dg-bogus "conversion from 'int' to 'unsigned char' may change value" }
+}
+
+int
+bar (const uc &a, const uc &b, const uc &c, int &d)
+{
+ return static_cast<uc>(static_cast<uc>((d++, a) << 1U) | b) | c; // { dg-bogus "conversion from 'int' to 'unsigned char' may change value" }
+}