================
@@ -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()),
+ unless(isFunctionTemplateSpecialization()), unless(isTemplate()))
+ .bind("function-params");
+
+ Finder->addMatcher(FunctionWithParams, this);
+ }
+}
+
+static void addConstFixits(DiagnosticBuilder &Diag, const VarDecl *Variable,
----------------
zeyi2 wrote:
I think there is a potential issue that we may generate FixIts for
redeclarations that live in system headers
(e.g. introduced by `-isystem`). IMHO this is usually undesirable and may fail
during apply-replacements. Could we still emit the diagnostic but skip
producing FixIts for those locations?
I think a possible implementation is to check
`Context.getSourceManager().isInSystemHeader(...)` first then apply the fix :)
It would also be nice if we can cover this scenario in the testcase.
https://github.com/llvm/llvm-project/pull/171215
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits