Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>,
Paul =?utf-8?q?Heidekrüger?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>
================
@@ -0,0 +1,227 @@
+// RUN: %check_clang_tidy -std=c++2b -check-suffix=DEFAULT %s \
+// RUN: cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses %t -- \
+// RUN: -config='{CheckOptions:
{cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses.ExcludeClasses:
"::ExcludedClass1;::ExcludedClass2"}}'
+
+// RUN: %check_clang_tidy -std=c++2b -check-suffix=AT %s \
+// RUN: cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses %t -- \
+// RUN: -config='{CheckOptions:
{cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses.ExcludeClasses:
"::ExcludedClass1;::ExcludedClass2", \
+// RUN:
cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses.SubscriptFixMode:
at}}'
+
+// RUN: %check_clang_tidy -std=c++2b -check-suffix=FUNC %s \
+// RUN: cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses %t -- \
+// RUN: -config='{CheckOptions:
{cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses.ExcludeClasses:
"::ExcludedClass1;::ExcludedClass2", \
+// RUN:
cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses.SubscriptFixMode:
function, \
+// RUN:
cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses.SubscriptFixFunction:
"f"}}'
+
+namespace std {
+ template<typename T, unsigned size>
+ struct array {
+ T operator[](unsigned i) {
+ return T{1};
+ }
+ T operator[]() {
+ return T{1};
+ }
+ T at(unsigned i) {
+ return T{1};
+ }
+ T at() {
+ return T{1};
+ }
+ };
+
+ template<typename T, typename V>
+ struct map {
+ T operator[](unsigned i) {
+ return T{1};
+ }
+ T at(unsigned i) {
+ return T{1};
+ }
+ };
+
+ template<typename T>
+ struct unique_ptr {
+ T operator[](unsigned i) {
+ return T{1};
+ }
+ };
+
+ template<typename T>
+ struct span {
+ T operator[](unsigned i) {
+ return T{1};
+ }
+ };
+} // namespace std
+
+namespace json {
+ template<typename T>
+ struct node{
+ T operator[](unsigned i) {
+ return T{1};
+ }
+ };
+} // namespace json
+
+struct SubClass : std::array<int, 3> {};
+
+class ExcludedClass1 {
+ public:
+ int operator[](unsigned i) {
+ return 1;
+ }
+ int at(unsigned i) {
+ return 1;
+ }
+};
+
+class ExcludedClass2 {
+ public:
+ int operator[](unsigned i) {
+ return 1;
+ }
+ int at(unsigned i) {
+ return 1;
+ }
+};
+
+template<class T> int f(T, unsigned){ return 0;}
+template<class T> int f(T){ return 0;}
+
+std::array<int, 3> a;
+
+auto b = a[0];
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:11: warning: possibly unsafe
'operator[]', consider bound-safe alternatives
[cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses]
+// CHECK-FIXES-AT: auto b = a.at(0);
+// CHECK-FIXES-FUNC: auto b = f(a, 0);
+
+auto b23 = a[];
----------------
carlosgalvezp wrote:
Is this code legal? What is the index?
https://github.com/llvm/llvm-project/pull/95220
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits