[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c9412441b87: [clang-tidy]mark record initList as non-const 
param (authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && 

[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-21 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 552199.
HerrCai0907 added a comment.

add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,24 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
+typedef XYConst XYConstAlias;
+// CHECK-MESSAGES: :[[@LINE+1]]:35: warning: pointer parameter 'x' can be pointer to const
+void recordInitListAliasDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListAliasDiag(const int *x) {{{$}}
+  XYConstAlias xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -241,6 +241,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 

[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-21 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM, but note that type aliases may not work properly, but that more a legacy 
issue that got source in line 104, simply because we should use canonical type 
there.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp:235
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}

Add a test with XYConst  hidden behind typedef.
like
```typedef XYConst XYConstTypedef;
XYConstTypedef yz = {x};
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

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


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-19 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551802.
HerrCai0907 added a comment.

fix typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-19 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:230
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

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


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551344.
HerrCai0907 added a comment.

update release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -227,6 +227,10 @@
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:234
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore

Please keep alphabetical order (by check name) in this section.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

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


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551030.
HerrCai0907 added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158152/new/

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,10 @@
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,10 @@
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang-tools-extra.

  struct XY {
int *x;
int *y;
  };
  void recordInitList(int *x) {
XY xy = {x, nullptr};
  }

x cannot be const int* becase it in a initialize list which only accept int*


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158152

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


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits