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

2017-12-06 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm abandoned this revision.
AndersRonnholm added a comment.

Fixed by https://reviews.llvm.org/rL319021. At least for c/c++ not sure if it 
handles objective-c.


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-12-05 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Fixed by https://reviews.llvm.org/rL319021?


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-09-08 Thread Aaron Ballman via Phabricator via cfe-commits
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(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



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-09-08 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm marked 2 inline comments as done.
AndersRonnholm added inline comments.



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:147
+if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+  if (const auto *F = dyn_cast(Parent)) {
+const auto ParDecl =

aaron.ballman wrote:
> What if the parent is an `ObjCMethodDecl` instead?
I don't think this checker handles objective-c


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-09-08 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm updated this revision to Diff 114346.
AndersRonnholm added a comment.
Herald added subscribers: xazax.hun, JDevlieghere.

Fixed comments


Repository:
  rL LLVM

https://reviews.llvm.org/D36672

Files:
  clang-tidy/readability/NonConstParameterCheck.cpp
  test/clang-tidy/readability-non-const-parameter.cpp


Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -277,3 +277,26 @@
 int x = *p;
   }
 };
+
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'i' can be
+int declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
+
+
+class D {
+private:
+  int declarationFixit(int *i);
+  // CHECK-FIXES: {{^}}  int declarationFixit(const int *i);{{$}}
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'i' can be
+int D::declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
Index: clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tidy/readability/NonConstParameterCheck.cpp
@@ -138,9 +138,20 @@
 if (!ParamInfo.CanBeConst)
   continue;
 
-diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
-<< Par->getName()
-<< FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+auto D = diag(Par->getLocation(),
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+
+const DeclContext *Parent = Par->getParentFunctionOrMethod();
+const auto *FD = dyn_cast(Parent);
+while (FD) {
+  const auto ParDecl = FD->getParamDecl(Par->getFunctionScopeIndex());
+  if (Par != ParDecl)
+D << ParDecl->getName()
+  << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
+  FD = FD->getPreviousDecl();
+}
   }
 }
 


Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -277,3 +277,26 @@
 int x = *p;
   }
 };
+
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'i' can be
+int declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
+
+
+class D {
+private:
+  int declarationFixit(int *i);
+  // CHECK-FIXES: {{^}}  int declarationFixit(const int *i);{{$}}
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'i' can be
+int D::declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
Index: clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tidy/readability/NonConstParameterCheck.cpp
@@ -138,9 +138,20 @@
 if (!ParamInfo.CanBeConst)
   continue;
 
-diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
-<< Par->getName()
-<< FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+auto D = diag(Par->getLocation(),
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+
+const DeclContext *Parent = Par->getParentFunctionOrMethod();
+const auto *FD = dyn_cast(Parent);
+while (FD) {
+  const auto ParDecl = FD->getParamDecl(Par->getFunctionScopeIndex());
+  if (Par != ParDecl)
+D << ParDecl->getName()
+  << FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
+  FD = FD->getPreviousDecl();
+}
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-08-16 Thread Aaron Ballman via Phabricator via cfe-commits
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(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(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



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-08-14 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

LGTM. But others should approve.


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits