[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
================
@@ -125,11 +125,38 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
.bind("arraySubscript");
Finder->addMatcher(STDArraySubscript, this);
+
+ // Catch signed char values passed to a <cctype>/<ctype.h> classification
+ // or conversion function; any value other than EOF or one representable
+ // as unsigned char is undefined behavior. Unlike the matchers above, this
+ // matches the uncast argument directly instead of going through
+ // charCastExpression(), because hasArgument() strips implicit casts off
+ // the argument before matching it.
+ const auto IntTypedef = qualType(hasDeclaration(typedefDecl(
+ hasAnyName(utils::options::parseStringList(CharTypedefsToIgnoreList)))));
+ const auto CctypeFunctionArgument =
+ callExpr(
+ callee(functionDecl(
+ hasAnyName("isalnum", "std::isalnum", "isalpha", "std::isalpha",
+ "isblank", "std::isblank", "iscntrl", "std::iscntrl",
----------------
zeyi2 wrote:
This currently would match unrelated functions such as `custom::isalpha` and `Classifier::toupper`. Please move the names into a static constexpr StringRef[] and restrict the matcher to global or std declarations (you can use `isInStdNamespace()` for this).
https://github.com/llvm/llvm-project/pull/211403
More information about the cfe-commits
mailing list