[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
Wed Aug 16 06:54:57 PDT 2017


aaron.ballman added inline comments.


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:146
+
+    if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+      if (const auto *F = dyn_cast<FunctionDecl>(Parent)) {
----------------
Please do not use `auto` here, as the type is not spelled out in the initialization.


================
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 =
----------------
What if the parent is an `ObjCMethodDecl` instead?


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:148-152
+        const auto ParDecl =
+            F->getFirstDecl()->getParamDecl(Par->getFunctionScopeIndex());
+        if (Par != ParDecl)
+          D << ParDecl->getName()
+            << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
----------------
Don't we need the fixit for *all* declarations of the function? e.g.,
```
char f(char *c); // Need it here
char f(char *c); // And here

char f(char *c) { // And here
  return *c;
}
```


Repository:
  rL LLVM

https://reviews.llvm.org/D36672





More information about the cfe-commits mailing list