CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
267 lines
12 KiB
C++
267 lines
12 KiB
C++
// RUN: %check_clang_tidy -std=c++17 %s modernize-avoid-c-arrays %t
|
|
|
|
#include <utility>
|
|
|
|
int a[] = {1, 2};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
int b[1];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
void foo() {
|
|
int c[b[0]];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C VLA arrays, use 'std::vector' instead
|
|
|
|
using d = decltype(c);
|
|
d e;
|
|
// Semi-FIXME: we do not diagnose these last two lines separately,
|
|
// because we point at typeLoc.getBeginLoc(), which is the decl before that
|
|
// (int c[b[0]];), which is already diagnosed.
|
|
}
|
|
|
|
template <typename T, int Size>
|
|
class array {
|
|
T d[Size];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
int e[1];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
|
};
|
|
|
|
array<int[4], 2> d;
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
using k = int[4];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
k ak;
|
|
// no diagnostic expected here since no concrete C-style array type is written here
|
|
|
|
array<k, 2> dk;
|
|
// no diagnostic expected here since no concrete C-style array type is written here
|
|
|
|
array<decltype(ak), 3> ek;
|
|
// no diagnostic expected here since no concrete C-style array type is written here
|
|
|
|
template <typename T>
|
|
class unique_ptr {
|
|
T *d;
|
|
|
|
int e[1];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
|
};
|
|
|
|
unique_ptr<int[]> d2;
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
using k2 = int[];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
unique_ptr<k2> dk2;
|
|
|
|
// Some header
|
|
extern "C" {
|
|
|
|
int f[] = {1, 2};
|
|
|
|
int j[1];
|
|
|
|
inline void bar() {
|
|
{
|
|
int j[j[0]];
|
|
}
|
|
}
|
|
|
|
extern "C++" {
|
|
int f3[] = {1, 2};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
int j3[1];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
struct Foo {
|
|
int f3[3] = {1, 2};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
|
|
|
int j3[1];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead
|
|
};
|
|
}
|
|
|
|
struct Bar {
|
|
|
|
int f[3] = {1, 2};
|
|
|
|
int j[1];
|
|
};
|
|
}
|
|
|
|
const char name[] = "Some string";
|
|
// 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' or 'std::vector' instead [modernize-avoid-c-arrays]
|
|
|
|
// within below template decl, no array type findings are expected within the template parameter declarations since not a single C-style array type got written explicitly
|
|
template <typename T,
|
|
bool = std::is_same_v<T, int>,
|
|
bool = std::is_same<T, int>::value,
|
|
bool = std::is_same_v<std::remove_const_t<T>, int>,
|
|
bool = std::is_same<std::remove_const_t<T>, int>::value,
|
|
bool = std::is_same_v<typename std::remove_const<T>::type, int>,
|
|
bool = std::is_same<typename std::remove_const<T>::type, int>::value,
|
|
std::enable_if_t<not(std::is_same_v<std::remove_const_t<T>, int>) && not(std::is_same_v<typename std::remove_const<T>::type, char>), bool> = true,
|
|
typename std::enable_if<not(std::is_same_v<std::remove_const_t<T>, int>) && not(std::is_same_v<typename std::remove_const<T>::type, char>), bool>::type = true,
|
|
typename = std::enable_if_t<not(std::is_same_v<std::remove_const_t<T>, int>) && not(std::is_same_v<typename std::remove_const<T>::type, char>)>,
|
|
typename = typename std::remove_const<T>::type,
|
|
typename = std::remove_const_t<T>>
|
|
class MyClassTemplate {
|
|
public:
|
|
// here, however, plenty of array type findings are expected for below template parameter declarations since C-style array types are written explicitly
|
|
template <typename U = T,
|
|
bool = std::is_same_v<U, int[]>,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
bool = std::is_same<U, int[10]>::value,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
std::enable_if_t<not(std::is_same_v<std::remove_const_t<U>, int[]>) && not(std::is_same_v<typename std::remove_const<U>::type, char[10]>), bool> = true,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:73: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:140: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
typename = typename std::remove_const<int[10]>::type,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:51: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
typename = std::remove_const_t<int[]>>
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
class MyInnerClassTemplate {
|
|
public:
|
|
MyInnerClassTemplate(const U&) {}
|
|
private:
|
|
U field[3];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
};
|
|
|
|
MyClassTemplate(const T&) {}
|
|
|
|
private:
|
|
T field[7];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
};
|
|
|
|
// an explicit instantiation
|
|
template
|
|
class MyClassTemplate<int[2]>;
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
using MyArrayType = int[3];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
// another explicit instantiation
|
|
template
|
|
class MyClassTemplate<MyArrayType>;
|
|
// no diagnostic is expected here since no C-style array type got written here
|
|
|
|
// within below template decl, no array type findings are expected within the template parameter declarations since not a single C-style array type got written explicitly
|
|
template <typename T,
|
|
bool = std::is_same_v<T, int>,
|
|
bool = std::is_same<T, int>::value,
|
|
bool = std::is_same_v<std::remove_const_t<T>, int>,
|
|
bool = std::is_same<std::remove_const_t<T>, int>::value,
|
|
bool = std::is_same_v<typename std::remove_const<T>::type, int>,
|
|
bool = std::is_same<typename std::remove_const<T>::type, int>::value,
|
|
std::enable_if_t<not(std::is_same_v<std::remove_const_t<T>, int>) && not(std::is_same_v<typename std::remove_const<T>::type, char>), bool> = true,
|
|
typename std::enable_if<not(std::is_same_v<std::remove_const_t<T>, int>) && not(std::is_same_v<typename std::remove_const<T>::type, char>), bool>::type = true,
|
|
typename = std::enable_if_t<not(std::is_same_v<std::remove_const_t<T>, int>) && not(std::is_same_v<typename std::remove_const<T>::type, char>)>,
|
|
typename = typename std::remove_const<T>::type,
|
|
typename = std::remove_const_t<T>>
|
|
void func(const T& param) {
|
|
int array1[1];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
T array2[2];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
T value;
|
|
}
|
|
|
|
// here, however, plenty of array type findings are expected for below template parameter declarations since C-style array types are written explicitly
|
|
template <typename T = int[],
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
bool = std::is_same_v<T, int[]>,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
bool = std::is_same<T, int[10]>::value,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
std::enable_if_t<not(std::is_same_v<std::remove_const_t<T>, int[]>) && not(std::is_same_v<typename std::remove_const<T>::type, char[10]>), bool> = true,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:71: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:138: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
typename = typename std::remove_const<int[10]>::type,
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
typename = std::remove_const_t<int[]>>
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
void fun(const T& param) {
|
|
int array3[3];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
T array4[4];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
T value;
|
|
}
|
|
|
|
template<typename T>
|
|
T some_constant{};
|
|
|
|
// explicit instantiations
|
|
template
|
|
int some_constant<int[5]>[5];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
template
|
|
int some_constant<decltype(ak)>[4];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
MyArrayType mk;
|
|
// no diagnostic is expected here since no C-style array type got written here
|
|
|
|
// explicit specializations
|
|
template<>
|
|
int some_constant<int[7]>[7]{};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
template<>
|
|
int some_constant<decltype(mk)>[3]{};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
void testArrayInTemplateType() {
|
|
int t[10];
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
func(t);
|
|
fun(t);
|
|
|
|
func<decltype(t)>({});
|
|
fun<decltype(t)>({});
|
|
|
|
func<int[1]>({});
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
fun<int[1]>({});
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
MyClassTemplate var{t};
|
|
MyClassTemplate<decltype(t)> var1{{}};
|
|
MyClassTemplate<int[2]> var2{{}};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
decltype(var1)::MyInnerClassTemplate var3{t};
|
|
decltype(var1)::MyInnerClassTemplate<decltype(t)> var4{{}};
|
|
decltype(var1)::MyInnerClassTemplate<char[5]> var5{{}};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
|
|
MyClassTemplate<decltype(t)>::MyInnerClassTemplate var6{t};
|
|
MyClassTemplate<decltype(t)>::MyInnerClassTemplate<decltype(t)> var7{{}};
|
|
MyClassTemplate<decltype(t)>::MyInnerClassTemplate<char[8]> var8{{}};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:54: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
MyClassTemplate<int[9]>::MyInnerClassTemplate<char[9]> var9{{}};
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
// CHECK-MESSAGES: :[[@LINE-2]]:49: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
|
|
}
|