[clang-tools-extra] Fix the issue #139467 ([clang-tidy] false positive narrowing conversion) (PR #139474)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Mon May 12 08:10:43 PDT 2025
================
@@ -554,15 +554,23 @@ bool NarrowingConversionsCheck::handleConditionalOperator(
// We have an expression like so: `output = cond ? lhs : rhs`
// From the point of view of narrowing conversion we treat it as two
// expressions `output = lhs` and `output = rhs`.
- handleBinaryOperator(Context, CO->getLHS()->getExprLoc(), Lhs,
- *CO->getLHS());
- handleBinaryOperator(Context, CO->getRHS()->getExprLoc(), Lhs,
- *CO->getRHS());
+ handleConditionalOperatorArgument(Context, Lhs, CO->getLHS());
+ handleConditionalOperatorArgument(Context, Lhs, CO->getRHS());
return true;
}
return false;
}
+void NarrowingConversionsCheck::handleConditionalOperatorArgument(
+ const ASTContext &Context, const Expr &Lhs, const Expr *Arg) {
+ if (const auto *ICE = llvm::dyn_cast<ImplicitCastExpr>(Arg)) {
+ if (!Arg->getIntegerConstantExpr(Context)) {
+ Arg = ICE->getSubExpr();
+ }
+ }
----------------
vbvictor wrote:
As per LLVM coding-style, there shouldn't be any braces for single-stmt ifs.
```cpp
if (const auto *ICE = llvm::dyn_cast<ImplicitCastExpr>(Arg))
if (!Arg->getIntegerConstantExpr(Context))
Arg = ICE->getSubExpr();
```
https://github.com/llvm/llvm-project/pull/139474
More information about the cfe-commits
mailing list