summaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-bitwise-compare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/warn-bitwise-compare.cpp')
-rw-r--r--test/SemaCXX/warn-bitwise-compare.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-bitwise-compare.cpp b/test/SemaCXX/warn-bitwise-compare.cpp
new file mode 100644
index 0000000000..894d4c581e
--- /dev/null
+++ b/test/SemaCXX/warn-bitwise-compare.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-bitwise-compare %s
+
+void test(int x) {
+ bool b1 = (8 & x) == 3;
+ // expected-warning@-1 {{bitwise comparison always evaluates to false}}
+ bool b2 = x | 5;
+ // expected-warning@-1 {{bitwise or with non-zero value always evaluates to true}}
+ bool b3 = (x | 5);
+ // expected-warning@-1 {{bitwise or with non-zero value always evaluates to true}}
+ bool b4 = !!(x | 5);
+ // expected-warning@-1 {{bitwise or with non-zero value always evaluates to true}}
+}