// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index]
intj=a[pos-1];
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead
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
}
voidg(){
inta[10];
for(inti=0;i<10;++i){
a[i]=i;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead
// CHECK-FIXES: gsl::at(a, i) = i;
gsl::at(a,i)=i;// OK, gsl::at() instead of []
}
a[-1]=3;// flagged by clang-diagnostic-array-bounds
a[10]=4;// flagged by clang-diagnostic-array-bounds
a[const_index(7)]=3;// flagged by clang-diagnostic-array-bounds
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