[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 Feb 19 12:06:11 PST 2025
================
@@ -11246,6 +11246,12 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
if (S.getLangOpts().OpenCL)
return;
+ if (LHS.get()->IgnoreParenImpCasts()->getType()->isBooleanType()) {
+ S.Diag(Loc, diag::warn_shift_bool)
+ << (Opc == BO_Shr) /*left|right*/ << LHS.get()->getSourceRange();
----------------
AaronBallman wrote:
As depressing as this is, it is used in the wild:
https://sourcegraph.com/search?q=context:global+lang:C%2B%2B+%5B+%5Ct%5C%28%5Dtrue%5Cs*%3C%3C%5Cs*.*&patternType=regexp&sm=0
https://sourcegraph.com/search?q=context:global+lang:C+%5B+%5Ct%5C%28%5Dtrue%5Cs*%3C%3C%5Cs*.*&patternType=regexp&sm=0
Not super often, but enough that it might be considered too chatty to enable by default.
https://github.com/llvm/llvm-project/pull/127336
More information about the cfe-commits
mailing list