[PATCH] D15332: new clang-tidy checker readability-non-const-parameter

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 18 08:34:13 PDT 2016


alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


================
Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:104
@@ +103,3 @@
+  const QualType T = Parm->getType();
+  if (!T->isPointerType() || T->getPointeeType().isConstQualified() ||
+      !(T->getPointeeType()->isIntegerType() ||
----------------
You're right. I was thinking about enums, but `isIntegerType` takes care of them too. As the next step, we should try to add all POD types, but that's a question for another patch.

================
Comment at: test/clang-tidy/readability-non-const-parameter.cpp:118-136
@@ +117,21 @@
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";
----------------
`PointerParameterConstnessCheck` is not much better, IMO. Maybe `readability-use-pointer-to-const-parameter`? Or just leave it like this for now.


https://reviews.llvm.org/D15332





More information about the cfe-commits mailing list