[clang-tools-extra] [clang-tidy] Fix a false positive when converting a bool to a signed integer type (PR #191696)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 12 05:02:30 PDT 2026


================
@@ -402,6 +402,9 @@ void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
       return;
     const BuiltinType *FromType = getBuiltinType(Rhs);
 
+    if (FromType->getKind() == BuiltinType::Bool)
----------------
zeyi2 wrote:

I understand that this is correct, but IIUC there is already a dedicated handler for bool-to-signed-integral conversions in [`handleBooleanToSignedIntegral`](https://github.com/llvm/llvm-project/blob/b7febd772c57fc21a126a8e125d749df9e4a6a53/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp#L484).

Would it make more sense to route this case there from the [`CK_IntegralCast`](https://github.com/llvm/llvm-project/blob/b7febd772c57fc21a126a8e125d749df9e4a6a53/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp#L596) path instead of special-casing it here?

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


More information about the cfe-commits mailing list