[clang] [Clang] add additional tests for -Wshift-bool (PR #130339)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 09:46:28 PDT 2025
================
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -Wshift-bool -verify %s
+
+void t() {
+ int x = 10;
+ int y = 1;
+
+ int a = y << x;
+ int b = y >> x;
+
+ int c = 0 << x;
+ int d = 0 >> x;
+
+ int e = y << 1;
+ int f = y >> 1;
+
+ int g = y << -1; // expected-warning {{shift count is negative}}
+ int h = y >> -1; // expected-warning {{shift count is negative}}
+
+ int i = y << 0;
+ int j = y >> 0;
+
+ if ((y << 1) != 0) { }
+ if ((y >> 1) != 0) { }
----------------
AaronBallman wrote:
No, ` (x < z) >> 1;` is what we want to test. In C++ `x < z` results in a `bool`. In C, it results in an `int`.
https://github.com/llvm/llvm-project/pull/130339
More information about the cfe-commits
mailing list