summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2015-11-18 02:14:35 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2015-11-18 02:14:35 +0000
commit67361cc2e1a3988aea7c4fdbc9bb0ee28d601cff (patch)
tree9e9b48fcc7c8d48b3dca95fe6c55ed90f1824724 /clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp
parent1cbe0e212a949b8491d14b5f23445ec52329e1dc (diff)
downloadbcm5719-llvm-67361cc2e1a3988aea7c4fdbc9bb0ee28d601cff.tar.gz
bcm5719-llvm-67361cc2e1a3988aea7c4fdbc9bb0ee28d601cff.zip
Revert r253401, "[clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-index"
cppcoreguidelines-pro-bounds-constant-array-index.cpp is failing in several hosts. llvm-svn: 253428
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp69
1 files changed, 0 insertions, 69 deletions
diff --git a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp
deleted file mode 100644
index aa19adf533e..00000000000
--- a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t -- -config='{CheckOptions: [{key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader, value: "dir1/gslheader.h"}]}' -- -std=c++11
-#include <array>
-// CHECK-FIXES: #include "dir1/gslheader.h"
-
-namespace gsl {
- template<class T, size_t N>
- T& at( T(&a)[N], size_t index );
-
- template<class T, size_t N>
- T& at( std::array<T, N> &a, size_t index );
-}
-
-constexpr int const_index(int base) {
- return base + 3;
-}
-
-void f(std::array<int, 10> a, int pos) {
- a [ pos / 2 /*comment*/] = 1;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not a compile-time constant; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index]
- // CHECK-FIXES: gsl::at(a, pos / 2 /*comment*/) = 1;
- int j = a[pos - 1];
- // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not a compile-time constant; use gsl::at() instead
- // CHECK-FIXES: int j = gsl::at(a, pos - 1);
-
- 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 before the beginning of the array [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
-}
-
-void g() {
- int a[10];
- for (int i = 0; i < 10; ++i) {
- a[i] = i;
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not a compile-time constant; 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
-}
-
-struct S {
- int& operator[](int i);
-};
-
-void customOperator() {
- S s;
- int i = 0;
- s[i] = 3; // OK, custom operator
-}
OpenPOWER on IntegriCloud