[clang-tools-extra] [clang-tidy] Add AnalyzeParameters option to misc-const-correctness (PR #171215)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 9 13:47:26 PST 2025


================
@@ -135,20 +147,83 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
           .bind("function-decl");
 
   Finder->addMatcher(FunctionScope, this);
+
+  if (AnalyzeParameters) {
+    const auto ParamMatcher =
+        parmVarDecl(unless(CommonExcludeTypes),
+                    anyOf(hasType(referenceType()), hasType(pointerType())))
+            .bind("param-var");
+
+    // Match function parameters which could be 'const' if not modified later.
+    // Example: `void foo(int* ptr)` would match `int* ptr`.
+    const auto FunctionWithParams =
+        functionDecl(
+            hasBody(stmt().bind("scope-params")),
+            has(typeLoc(forEach(ParamMatcher))), unless(cxxMethodDecl()),
----------------
vbvictor wrote:

Currently, ExprMutationAnalyzer can't handle init-list in ctors like `B::B(int x) : A(x)`, and I also don't want to deal with virtual/override for now because it brings complexity to an already big patch.
I'll look into Methods later.

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


More information about the cfe-commits mailing list