[clang-tools-extra] [clang-tidy]suggest use `std::span` as replacement of c array in C++20 for modernize-avoid-c-arrays (PR #108555)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 07:14:57 PDT 2024
================
@@ -1,9 +1,9 @@
-// RUN: %check_clang_tidy %s modernize-avoid-c-arrays %t -- \
+// RUN: %check_clang_tidy -std=c++17 %s modernize-avoid-c-arrays %t -- \
// RUN: -config='{CheckOptions: { modernize-avoid-c-arrays.AllowStringArrays: true }}'
const char name[] = "name";
const char array[] = {'n', 'a', 'm', 'e', '\0'};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]
void takeCharArray(const char name[]);
-// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, use std::vector<> instead [modernize-avoid-c-arrays]
----------------
HerrCai0907 wrote:
Actually not. How can you replace `void takeCharArray(const char name[]);` with `std::array` if you don't know the array size. In C++20, we can use `std::span` but for C++11, the ref of `std::vector` or maybe `std::string` (but I think this check should not introduce `std::string`) is the only choice.
https://github.com/llvm/llvm-project/pull/108555
More information about the cfe-commits
mailing list