@@ -32,7 +32,14 @@ array<int[4], 2> d;
3232using k = int [4 ];
3333// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not declare C-style arrays, use 'std::array' instead
3434
35+ k ak;
36+ // no diagnostic expected here since no concrete c-array type is written here
37+
3538array<k, 2 > dk;
39+ // no diagnostic expected here since no concrete c-array type is written here
40+
41+ array<decltype (ak), 3 > ek;
42+ // no diagnostic expected here since no concrete c-array type is written here
3643
3744template <typename T>
3845class unique_ptr {
@@ -92,3 +99,188 @@ const char name[] = "Some string";
9299
93100void takeCharArray (const char name[]);
94101// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead [modernize-avoid-c-arrays]
102+
103+ namespace std {
104+ template <class T , class U >
105+ struct is_same { constexpr static bool value{false }; };
106+
107+ template <class T >
108+ struct is_same <T, T> { constexpr static bool value{true }; };
109+
110+ template <class T , class U >
111+ constexpr bool is_same_v = is_same<T, U>::value;
112+
113+ template <class T > struct remove_const { typedef T type; };
114+ template <class T > struct remove_const <const T> { typedef T type; };
115+
116+ template <class T >
117+ using remove_const_t = typename remove_const<T>::type;
118+
119+ template <bool B, class T = void > struct enable_if {};
120+ template <class T > struct enable_if <true , T> { typedef T type; };
121+
122+ template < bool B, class T = void >
123+ using enable_if_t = typename enable_if<B, T>::type;
124+ }
125+
126+ // below, no array type findings are expected within the template parameter declarations since no array type gets written explicitly
127+ template <typename T,
128+ bool = std::is_same_v<T, int >,
129+ bool = std::is_same<T, int >::value,
130+ bool = std::is_same_v<std::remove_const_t <T>, int >,
131+ bool = std::is_same<std::remove_const_t <T>, int >::value,
132+ bool = std::is_same_v<typename std::remove_const<T>::type, int >,
133+ bool = std::is_same<typename std::remove_const<T>::type, int >::value,
134+ 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 ,
135+ 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 ,
136+ 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 >)>,
137+ typename = typename std::remove_const<T>::type,
138+ typename = std::remove_const_t <T>>
139+ class MyClassTemplate {
140+ public:
141+ // here, plenty of array type findings are expected for below template parameter declarations since array types get written explicitly
142+ template <typename U = T,
143+ bool = std::is_same_v<U, int []>,
144+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
145+ bool = std::is_same<U, int [10 ]>::value,
146+ // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
147+ 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 ,
148+ // CHECK-MESSAGES: :[[@LINE-1]]:73: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
149+ // CHECK-MESSAGES: :[[@LINE-2]]:140: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
150+ typename = typename std::remove_const<int [10 ]>::type,
151+ // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
152+ typename = std::remove_const_t <int []>>
153+ // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
154+ class MyInnerClassTemplate {
155+ public:
156+ MyInnerClassTemplate (const U&) {}
157+ private:
158+ U field[3 ];
159+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
160+ };
161+
162+ MyClassTemplate (const T&) {}
163+
164+ private:
165+ T field[7 ];
166+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
167+ };
168+
169+ // an explicit instantiation
170+ template
171+ class MyClassTemplate <int [2 ]>;
172+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
173+
174+ using MyArrayType = int [3 ];
175+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
176+
177+ // another explicit instantiation
178+ template
179+ class MyClassTemplate <MyArrayType>;
180+ // no diagnostic is expected here since no C-style array type got written here
181+
182+ // below, no array type findings are expected within the template parameter declarations since no array type gets written explicitly
183+ template <typename T,
184+ bool = std::is_same_v<T, int >,
185+ bool = std::is_same<T, int >::value,
186+ bool = std::is_same_v<std::remove_const_t <T>, int >,
187+ bool = std::is_same<std::remove_const_t <T>, int >::value,
188+ bool = std::is_same_v<typename std::remove_const<T>::type, int >,
189+ bool = std::is_same<typename std::remove_const<T>::type, int >::value,
190+ 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 ,
191+ 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 ,
192+ 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 >)>,
193+ typename = typename std::remove_const<T>::type,
194+ typename = std::remove_const_t <T>>
195+ void func (const T& param) {
196+ int array1[1 ];
197+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
198+
199+ T array2[2 ];
200+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
201+
202+ T value;
203+ }
204+
205+ // here, plenty of array type findings are expected for below template parameter declarations since array types get written explicitly
206+ template <typename T = int [],
207+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
208+ bool = std::is_same_v<T, int []>,
209+ // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
210+ bool = std::is_same<T, int [10 ]>::value,
211+ // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
212+ 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 ,
213+ // CHECK-MESSAGES: :[[@LINE-1]]:71: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
214+ // CHECK-MESSAGES: :[[@LINE-2]]:138: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
215+ typename = typename std::remove_const<int [10 ]>::type,
216+ // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
217+ typename = std::remove_const_t <int []>>
218+ // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
219+ void fun (const T& param) {
220+ int array3[3 ];
221+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
222+
223+ T array4[4 ];
224+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
225+
226+ T value;
227+ }
228+
229+ template <typename T>
230+ T some_constant{};
231+
232+ // explicit instantiations
233+ template
234+ int some_constant<int [5 ]>[5 ];
235+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
236+
237+ template
238+ int some_constant<decltype (ak)>[4 ];
239+ // no diagnostic is expected here since explicit instantiations aren't represented as `TypeLoc` in the AST and we hence cannot match them as such
240+
241+ MyArrayType mk;
242+ // no diagnostic is expected here since no C-style array type got written here
243+
244+ // explicit specializations
245+ template <>
246+ int some_constant<int [7 ]>[7 ]{};
247+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
248+ // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
249+
250+ template <>
251+ int some_constant<decltype (mk)>[3 ]{};
252+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
253+
254+ void testArrayInTemplateType () {
255+ int t[10 ];
256+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
257+
258+ func (t);
259+ fun (t);
260+
261+ func<decltype (t)>({});
262+ fun<decltype (t)>({});
263+
264+ func<int [1 ]>({});
265+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
266+ fun<int [1 ]>({});
267+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
268+
269+ MyClassTemplate var{t};
270+ MyClassTemplate<decltype (t)> var1{{}};
271+ MyClassTemplate<int [2 ]> var2{{}};
272+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
273+
274+ decltype (var1)::MyInnerClassTemplate var3{t};
275+ decltype (var1)::MyInnerClassTemplate<decltype (t)> var4{{}};
276+ decltype (var1)::MyInnerClassTemplate<char [5 ]> var5{{}};
277+ // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
278+
279+ MyClassTemplate<decltype (t)>::MyInnerClassTemplate var6{t};
280+ MyClassTemplate<decltype (t)>::MyInnerClassTemplate<decltype (t)> var7{{}};
281+ MyClassTemplate<decltype (t)>::MyInnerClassTemplate<char [8 ]> var8{{}};
282+ // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
283+ MyClassTemplate<int [9 ]>::MyInnerClassTemplate<char [9 ]> var9{{}};
284+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
285+ // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
286+ }
0 commit comments