[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 10:57:38 PST 2025


================
@@ -11247,6 +11247,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
   if (S.getLangOpts().OpenCL)
     return;
 
+  if (Opc == BO_Shr &&
+      LHS.get()->IgnoreParenImpCasts()->getType()->isBooleanType()) {
+    S.Diag(Loc, diag::warn_shift_bool) << LHS.get()->getSourceRange();
+    return;
----------------
AaronBallman wrote:

I don't think we want to return here, don't we want the rest of the checking? e.g.,

`true >> -1` should get both the shift bool warning and the negative shift warning?

https://github.com/llvm/llvm-project/pull/127336


More information about the cfe-commits mailing list