[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 03:27:45 PST 2025
================
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -Wshift-bool -verify %s
+
+void t() {
+ int x = 10;
+ bool y = true;
+
+ bool a = y >> x; // expected-warning {{right shifting a `bool` implicitly converts it to 'int'}}
+ bool b = false >> x; // expected-warning {{right shifting a `bool` implicitly converts it to 'int'}}
+ bool c = y >> 5; // expected-warning {{right shifting a `bool` implicitly converts it to 'int'}}
+ bool d = y >> -1; // expected-warning {{right shifting a `bool` implicitly converts it to 'int'}}
+ bool e = y >> 0; // expected-warning {{right shifting a `bool` implicitly converts it to 'int'}}
----------------
Fznamznon wrote:
Can we also check that clang doesn't warn on left shift? Can we also add a test checking something like
```
if ((y >> 2) != 7) // expected-warning
```
https://github.com/llvm/llvm-project/pull/127336
More information about the cfe-commits
mailing list