[clang-tools-extra] [clang-tidy] Add AnalyzeParameters option to misc-const-correctness (PR #171215)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 15 15:05:27 PST 2026
================
@@ -112,47 +122,93 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
const auto FunctionPointerRef =
hasType(hasCanonicalType(referenceType(pointee(functionType()))));
+ const auto CommonExcludeTypes =
+ anyOf(ConstType, ConstReference, RValueReference, TemplateType,
+ FunctionPointerRef, hasType(cxxRecordDecl(isLambda())),
+ AutoTemplateType, isImplicit(), AllowedType);
+
// Match local variables which could be 'const' if not modified later.
// Example: `int i = 10` would match `int i`.
- const auto LocalValDecl = varDecl(
- isLocal(), hasInitializer(anything()),
- unless(anyOf(ConstType, ConstReference, TemplateType,
- hasInitializer(isInstantiationDependent()), AutoTemplateType,
- RValueReference, FunctionPointerRef,
- hasType(cxxRecordDecl(isLambda())), isImplicit(),
- AllowedType)));
+ const auto LocalValDecl =
+ varDecl(isLocal(), hasInitializer(unless(isInstantiationDependent())),
+ unless(CommonExcludeTypes));
// Match the function scope for which the analysis of all local variables
// shall be run.
const auto FunctionScope =
- functionDecl(
- hasBody(stmt(forEachDescendant(
- declStmt(containsAnyDeclaration(
- LocalValDecl.bind("local-value")),
- unless(has(decompositionDecl())))
- .bind("decl-stmt")))
- .bind("scope")))
+ functionDecl(hasBody(stmt(forEachDescendant(
+ declStmt(containsAnyDeclaration(
+ LocalValDecl.bind("value")),
+ unless(has(decompositionDecl())))
+ .bind("decl-stmt")))
+ .bind("scope")))
.bind("function-decl");
Finder->addMatcher(FunctionScope, this);
+
+ if (AnalyzeParameters) {
+ const auto ParamMatcher =
+ parmVarDecl(unless(CommonExcludeTypes),
+ anyOf(hasType(referenceType()), hasType(pointerType())))
----------------
5chmidti wrote:
Sure, sounds good to me
https://github.com/llvm/llvm-project/pull/171215
More information about the cfe-commits
mailing list