[clang-tools-extra] [clang-tidy] Fix false positives in `bugprone-signed-char-misuse` (PR #149790)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 21 03:55:23 PDT 2025
=?utf-8?q?Björn?= Svensson <bjorn.a.svensson at est.tech>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/149790 at github.com>
================
@@ -75,16 +86,21 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
const auto UnSignedCharCastExpr =
charCastExpression(false, IntegerType, "unsignedCastExpression");
- // Catch assignments with signed char -> integer conversion.
+ // Catch assignments with signed char -> integer conversion. Ignore false
+ // positives on C23 enums with the fixed underlying type of signed char.
const auto AssignmentOperatorExpr =
expr(binaryOperator(hasOperatorName("="), hasLHS(hasType(IntegerType)),
- hasRHS(SignedCharCastExpr)));
+ hasRHS(SignedCharCastExpr)),
+ unless(allOf(isC23Stmt(), binaryOperator(hasLHS(hasType(
+ hasCanonicalType(enumType())))))));
----------------
vbvictor wrote:
And new matchers `isC23` are obsolete
https://github.com/llvm/llvm-project/pull/149790
More information about the cfe-commits
mailing list