[clang-tools-extra] [clang-tidy] Catch <cctype> function args in bugprone-signed-char-misuse (PR #211403)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 3 02:30:41 PDT 2026


================
@@ -138,8 +165,7 @@ void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
   // The potential misinterpretation happens for negative values only.
   Expr::EvalResult EVResult;
   if (!SignedCastExpression->isValueDependent() &&
-      SignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
-                                                        *Result.Context)) {
+      SignedCastExpression->EvaluateAsInt(EVResult, *Result.Context)) {
----------------
zeyi2 wrote:

This appears to regress existing behavior:

```cpp
int read(int *values) {
  constexpr signed char index = -1;
  return values[static_cast<unsigned int>(index)];
}
```

It would give a warning before: https://clang-tidy.godbolt.org/z/xWa9fT9sY

Could we preserve `getSubExpr()` evaluation for the existing matchers and handle the `cctype` argument separately?

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


More information about the cfe-commits mailing list