[PATCH] D36672: [clang-tidy] readability-non-const-parameter: fixit on all function declarations

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 07:31:41 PDT 2017


aaron.ballman added inline comments.


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:147
+    if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+      if (const auto *F = dyn_cast<FunctionDecl>(Parent)) {
+        const auto ParDecl =
----------------
AndersRonnholm wrote:
> aaron.ballman wrote:
> > What if the parent is an `ObjCMethodDecl` instead?
> I don't think this checker handles objective-c
I think it does -- it has a matcher for `ParmVarDecl`, which can be contained by an `ObjCMethodDecl`.


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:143
+                  "pointer parameter '%0' can be pointer to const")
+             << Par->getName()
+             << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
----------------
You should remove the quotes around %0 and drop the `getName()` -- the diagnostics engine automatically handled `NamedDecl` subclasses and properly quotes them.


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:149
+    while (FD) {
+      const auto ParDecl = FD->getParamDecl(Par->getFunctionScopeIndex());
+      if (Par != ParDecl)
----------------
`const auto *`


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:151
+      if (Par != ParDecl)
+        D << ParDecl->getName()
+          << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
----------------
You can drop the `getName()` call here as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D36672





More information about the cfe-commits mailing list