[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-08-25 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

thanks for the review. can you please land it for me pls? Jorge Pinto Sousa 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156624

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


[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-08-24 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

@PiotrZSL @carlosgalvezp can you please recheck?


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

https://reviews.llvm.org/D156624

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


[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-08-24 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 553062.

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

https://reviews.llvm.org/D156624

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -23,6 +23,9 @@
   return base + 3;
 }
 
+template
+class DerivedArray : public std::array {};
+
 void f(std::array a, int pos) {
   a [ pos / 2 /*comment*/] = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
@@ -68,6 +71,81 @@
   m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
+template
+class PrivateDerivedArray : std::array {
+public:
+  T& operator[](size_t n){
+return std::array::operator[](static_cast(n));
+  };
+  T& at(size_t n) {
+return std::array::at(static_cast(n));
+  };
+};
+
+void f_derived(DerivedArray a, int pos) {
+  a [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int j = a[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not an integer constant expression
+
+  a.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
+
+  a[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  a[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  a[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  a[0] = 3; // OK, constant index and inside bounds
+  a[1] = 3; // OK, constant index and inside bounds
+  a[9] = 3; // OK, constant index and inside bounds
+  a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = DerivedArray;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyPrivateArray = PrivateDerivedArray;
+  MyPrivateArray pm{};
+  pm [ pos / 2 /*comment*/] = 1;
+  int jjj = pm[pos - 1];
+
+  pm.at(pos-1) = 2; // OK, at() instead of []
+  pm[-1] = 3;
+  pm[10] = 4;
+
+  pm[const_index(7)] = 3;
+
+  pm[0] = 3; // OK, constant index and inside bounds
+  pm[1] = 3; // OK, constant index and inside bounds
+  pm[9] = 3; // OK, constant index and inside bounds
+  pm[const_index(6)] = 3; // OK, constant index and inside bounds
+}
+
+
+
+
 void g() {
   int a[10];
   for (int i = 0; i < 10; ++i) {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -196,6 +196,10 @@
   ` check
   to ignore predefined expression (e.g., ``__func__``, ...).
 
+- Improved :doc:`cppcoreguidelines-pro-bounds-constant-array-index
+  ` check
+  to perform checks on derived classes of  ``std::array``.
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: 

[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-07-30 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

In D156624#4545107 , @PiotrZSL wrote:

> Good, just verify that documentation for this check is still proper, and add 
> entry in release notes about this change.

I missed those, I will sure ^^

In D156624#4545117 , @carlosgalvezp 
wrote:

> What about the use case of privately inheriting `std::array`, and overriding 
> the `operator[]` there with bounds check? I believe there shouldn't be 
> warnings there.
>
> Would it be possible to check only _public_ inheritance?

Good point, I cannot think of an _easy_ way to check it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156624

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


[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-07-30 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

hi @PiotrZSL, thanks for the review :) can you please land it for me?

Jorge Pinto Sousa 


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

https://reviews.llvm.org/D156624

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


[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-07-30 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, arphaman, kbarton, 
xazax.hun, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
sousajo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Index accessing checks are not performed for derived classes of
of `std::array`, as only `std::array` itself and its aliases
seems to be checked.

  

This patch aims to extend it for derived classes such as:

  template
  class DerivedArray : public std::array {};


https://reviews.llvm.org/D156624

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -23,6 +23,9 @@
   return base + 3;
 }
 
+template
+class DerivedArray : public std::array {};
+
 void f(std::array a, int pos) {
   a [ pos / 2 /*comment*/] = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
@@ -68,6 +71,51 @@
   m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
+void f_derived(DerivedArray a, int pos) {
+  a [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int j = a[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  a.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
+
+  a[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  a[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  a[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  a[0] = 3; // OK, constant index and inside bounds
+  a[1] = 3; // OK, constant index and inside bounds
+  a[9] = 3; // OK, constant index and inside bounds
+  a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = DerivedArray;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
+}
+
 void g() {
   int a[10];
   for (int i = 0; i < 10; ++i) {
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -50,7 +50,8 @@
   hasOverloadedOperatorName("[]"),
   hasArgument(
   0, hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
- cxxRecordDecl(hasName("::std::array")).bind("type")),
+ 
cxxRecordDecl(isSameOrDerivedFrom(hasName("::std::array")))
+ .bind("type")),
   hasArgument(1, expr().bind("index")))
   .bind("expr"),
   this);


Index: 

[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-03 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

while landing it, if someone feels that the release work can be reworded please 
feel free to do so.


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

https://reviews.llvm.org/D154297

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


[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-02 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 536622.
sousajo added a comment.

Thanks ^^ added the release note. Can someone please land it for me?

Jorge Pinto Sousa 


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

https://reviews.llvm.org/D154297

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
 void g() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -325,6 +325,10 @@
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
 
+- Improved :doc:`cppcoreguidelines-pro-bounds-constant-array-index
+  ` to 
also check
+  for ``std::array`` type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -49,7 +49,8 @@
   cxxOperatorCallExpr(
   hasOverloadedOperatorName("[]"),
   hasArgument(
-  0, hasType(cxxRecordDecl(hasName("::std::array")).bind("type"))),
+  0, hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasName("::std::array")).bind("type")),
   hasArgument(1, expr().bind("index")))
   .bind("expr"),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the 

[PATCH] D154297: clang-tidy: accessing checks not done for aliases of `std::array`

2023-07-02 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, jeroen.dobbelaere, arphaman, 
kbarton, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
sousajo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Index accessing checks are not performed for aliases
of `std::array`, as only `std::array` itself seems to be checked.

This patchs aims to extend it for aliases such as:
 `using MyArray = std::array;`


https://reviews.llvm.org/D154297

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when 
the index is not an integer constant expression 
[cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when 
the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is 
negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements) 
[cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past 
the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
 void g() {
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
@@ -49,7 +49,8 @@
   cxxOperatorCallExpr(
   hasOverloadedOperatorName("[]"),
   hasArgument(
-  0, hasType(cxxRecordDecl(hasName("::std::array")).bind("type"))),
+  0, hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+ cxxRecordDecl(hasName("::std::array")).bind("type")),
   hasArgument(1, expr().bind("index")))
   .bind("expr"),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -44,6 +44,28 @@
   a[1] = 3; // OK, constant index and inside bounds
   a[9] = 3; // OK, constant index and inside bounds
   a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = std::array;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside 

[PATCH] D148276: [clang] trigger -Wcast-qual on functional casts

2023-05-06 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

have been sick, and could not advance much except I added the tests to 
replicate the issue. Any ideas on how to proceed here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148276

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


[PATCH] D148276: [clang] trigger -Wcast-qual on functional casts

2023-04-21 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

In D148276#4288236 , @aaron.ballman 
wrote:

> In D148276#4288145 , @sousajo wrote:
>
>> hey :( I will try to investigate it a bit sometime next week ^^ thanks for 
>> pointing it out
>
> Thank you for looking into it! I didn't think about `remove_const`, 
> `remove_cv`, etc. when considering test cases, sorry about that!

No worries :) Ill add those and try to craft a fix. If I am really lost I also 
let you know ^^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148276

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


[PATCH] D148276: [clang] trigger -Wcast-qual on functional casts

2023-04-21 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

hey :( I will try to investigate it a bit sometime next week ^^ thanks for 
pointing it out


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148276

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


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-16 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

cannot reproduce the build failure locally. if this looks fine can someone land 
it for me? or should we wait until we have a green build after rebase?


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

https://reviews.llvm.org/D148437

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


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-16 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 513969.
sousajo added a comment.

- rebased


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

https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-15 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 513946.
sousajo added a comment.

- inline string to be checked


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

https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-15 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 513945.
sousajo added a comment.

- removed `FormatStyle Style = getLLVMStyle();` as llvm is the default style


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

https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,14 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  constexpr StringRef Code("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}\n");
+  verifyFormat(Code);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,14 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  constexpr StringRef Code("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}\n");
+  verifyFormat(Code);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-15 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

As I dont have commit access if someone can land It for me:

Jorge Pinto Sousa 



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

https://reviews.llvm.org/D148437

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


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-15 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
sousajo added a reviewer: MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan.
sousajo requested review of this revision.

Fixes: https://github.com/llvm/llvm-project/issues/53173


https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,16 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsFieldName) {
+  FormatStyle Style = getLLVMStyle();
+
+  constexpr StringRef Code("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}\n");
+  verifyFormat(Code, Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,16 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsFieldName) {
+  FormatStyle Style = getLLVMStyle();
+
+  constexpr StringRef Code("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}\n");
+  verifyFormat(Code, Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148354: [clang-tidy][NFC] Remove reference to Visual studio native plugin

2023-04-14 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

In D148354#4269013 , @PiotrZSL wrote:

> I see you uploaded this path without author attached, should I push this as 
> "Jorge Pinto Sousa " ?

Yes please do thanks :)


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

https://reviews.llvm.org/D148354

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


[PATCH] D148354: [clang-tidy] Remove reference to Visual studio native plugin

2023-04-14 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
sousajo added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
sousajo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The clang-tidy documentation contained:

> MS Visual Studio has a native clang-tidy-vs plugin

This plugin was removed via 559ae14.

Fixes: https://github.com/llvm/llvm-project/issues/62142


https://reviews.llvm.org/D148354

Files:
  clang-tools-extra/docs/clang-tidy/Integrations.rst


Index: clang-tools-extra/docs/clang-tidy/Integrations.rst
===
--- clang-tools-extra/docs/clang-tidy/Integrations.rst
+++ clang-tools-extra/docs/clang-tidy/Integrations.rst
@@ -82,13 +82,11 @@
 .. _ReSharper C++: 
https://www.jetbrains.com/help/resharper/Clang_Tidy_Integration.html
 .. _Visual Assist: https://docs.wholetomato.com/default.asp?W761
 .. _Clang Power Tools: 
https://marketplace.visualstudio.com/items?itemName=caphyon.ClangPowerTools
-.. _clang-tidy-vs: 
https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clang-tidy-vs
 
-`MS Visual Studio`_ has a native clang-tidy-vs_ plugin and also can integrate
-:program:`clang-tidy` by means of three other tools. The `ReSharper C++`_
-extension, version 2017.3 and later, provides seamless :program:`clang-tidy`
-integration: checks and quick-fixes run alongside native inspections. Apart
-from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
+`MS Visual Studio`_  can integrate :program:`clang-tidy` by means of three 
different tools.
+The `ReSharper C++`_ extension, version 2017.3 and later, provides seamless
+:program:`clang-tidy` integration: checks and quick-fixes run alongside native 
inspections.
+Apart from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
 step of its code clean-up process. `Visual Assist`_ build 2210 includes a
 subset of :program:`clang-tidy` checklist to inspect the code as you edit.
 Another way to bring :program:`clang-tidy` functionality to Visual Studio is


Index: clang-tools-extra/docs/clang-tidy/Integrations.rst
===
--- clang-tools-extra/docs/clang-tidy/Integrations.rst
+++ clang-tools-extra/docs/clang-tidy/Integrations.rst
@@ -82,13 +82,11 @@
 .. _ReSharper C++: https://www.jetbrains.com/help/resharper/Clang_Tidy_Integration.html
 .. _Visual Assist: https://docs.wholetomato.com/default.asp?W761
 .. _Clang Power Tools: https://marketplace.visualstudio.com/items?itemName=caphyon.ClangPowerTools
-.. _clang-tidy-vs: https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clang-tidy-vs
 
-`MS Visual Studio`_ has a native clang-tidy-vs_ plugin and also can integrate
-:program:`clang-tidy` by means of three other tools. The `ReSharper C++`_
-extension, version 2017.3 and later, provides seamless :program:`clang-tidy`
-integration: checks and quick-fixes run alongside native inspections. Apart
-from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
+`MS Visual Studio`_  can integrate :program:`clang-tidy` by means of three different tools.
+The `ReSharper C++`_ extension, version 2017.3 and later, provides seamless
+:program:`clang-tidy` integration: checks and quick-fixes run alongside native inspections.
+Apart from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
 step of its code clean-up process. `Visual Assist`_ build 2210 includes a
 subset of :program:`clang-tidy` checklist to inspect the code as you edit.
 Another way to bring :program:`clang-tidy` functionality to Visual Studio is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147874: [clang-tidy] Fix AST Library documentation link

2023-04-09 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

I dont have commit access, can someone land it for me?

Name: Jorge Pinto Sousa
Email: 


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

https://reviews.llvm.org/D147874

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


[PATCH] D147874: [clang-tidy] Fix AST Library documentation link

2023-04-09 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
sousajo added reviewers: LegalizeAdulthood, vtjnash.
Herald added subscribers: PiotrZSL, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
sousajo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The link was pointing to the 'Lexer and Preprocessor Library'
instead.


https://reviews.llvm.org/D147874

Files:
  clang-tools-extra/docs/clang-tidy/Contributing.rst


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -278,7 +278,7 @@
   for information about tokens, lexing (transforming characters into tokens) 
and the
   preprocessor.
 - `The AST Library
-  
`_
+  `_
   for information about how C++ source statements are represented as an 
abstract syntax
   tree (AST).
 


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -278,7 +278,7 @@
   for information about tokens, lexing (transforming characters into tokens) and the
   preprocessor.
 - `The AST Library
-  `_
+  `_
   for information about how C++ source statements are represented as an abstract syntax
   tree (AST).
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits