Expand the coverage of the warning for constants on the RHS of logical operands:
return f() || -1;
where the user meant to write '|'.
This bootstraps without any additional warnings.
Patch by Richard Trieu.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132327 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/expressions.cpp b/test/SemaCXX/expressions.cpp
index c4e9dcc..95ece48 100644
--- a/test/SemaCXX/expressions.cpp
+++ b/test/SemaCXX/expressions.cpp
@@ -32,3 +32,34 @@
bar(x += E_zero); // expected-error {{incompatible type}}
}
}
+
+int test2(int x) {
+ return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+
+ return x && sizeof(int) == 4; // no warning, RHS is logical op.
+ return x && true;
+ return x && false;
+ return x || true;
+ return x || false;
+
+ return x && (unsigned)0; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+
+ return x || (unsigned)1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+
+ return x || 0; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || 1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || -1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || 5; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x && 0; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && 1; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && -1; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && 5; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x || (0); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || (1); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || (-1); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || (5); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x && (0); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && (1); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && (-1); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && (5); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+}