@@ -92,3 +92,162 @@ const char name[] = "Some string";
9292
9393void takeCharArray (const char name[]);
9494// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, use 'std::array' or 'std::vector' instead [modernize-avoid-c-arrays]
95+
96+ namespace std {
97+ template <class T , class U >
98+ struct is_same { constexpr static bool value{false }; };
99+
100+ template <class T >
101+ struct is_same <T, T> { constexpr static bool value{true }; };
102+
103+ template <class T , class U >
104+ constexpr bool is_same_v = is_same<T, U>::value;
105+
106+ template <class T > struct remove_const { typedef T type; };
107+ template <class T > struct remove_const <const T> { typedef T type; };
108+
109+ template <class T >
110+ using remove_const_t = typename remove_const<T>::type;
111+
112+ template <bool B, class T = void > struct enable_if {};
113+ template <class T > struct enable_if <true , T> { typedef T type; };
114+
115+ template < bool B, class T = void >
116+ using enable_if_t = typename enable_if<B, T>::type;
117+ }
118+
119+ // below, no array type findings are expected within the template parameter declarations since no array type gets written explicitly
120+ template <typename T,
121+ bool = std::is_same_v<T, int >,
122+ bool = std::is_same<T, int >::value,
123+ bool = std::is_same_v<std::remove_const_t <T>, int >,
124+ bool = std::is_same<std::remove_const_t <T>, int >::value,
125+ bool = std::is_same_v<typename std::remove_const<T>::type, int >,
126+ bool = std::is_same<typename std::remove_const<T>::type, int >::value,
127+ 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 ,
128+ 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 ,
129+ 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 >)>,
130+ typename = typename std::remove_const<T>::type,
131+ typename = std::remove_const_t <T>>
132+ class MyClassTemplate {
133+ public:
134+ // here, plenty of array type findings are expected for below template parameter declarations since array types get written explicitly
135+ template <typename U = T,
136+ bool = std::is_same_v<U, int []>,
137+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
138+ bool = std::is_same<U, int [10 ]>::value,
139+ // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
140+ 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 ,
141+ // CHECK-MESSAGES: :[[@LINE-1]]:73: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
142+ // CHECK-MESSAGES: :[[@LINE-2]]:140: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
143+ typename = typename std::remove_const<int [10 ]>::type,
144+ // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
145+ typename = std::remove_const_t <int []>>
146+ // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
147+ class MyInnerClassTemplate {
148+ public:
149+ MyInnerClassTemplate (const U&) {}
150+ private:
151+ U field[3 ];
152+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
153+ };
154+
155+ MyClassTemplate (const T&) {}
156+
157+ private:
158+ T field[7 ];
159+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
160+ };
161+
162+ // an explicit instantiation
163+ template
164+ class MyClassTemplate <int [2 ]>;
165+ // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
166+
167+ using MyArrayType = int [3 ];
168+ // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
169+
170+ // another explicit instantiation
171+ template
172+ class MyClassTemplate <MyArrayType>;
173+
174+ // below, no array type findings are expected within the template parameter declarations since no array type gets written explicitly
175+ template <typename T,
176+ bool = std::is_same_v<T, int >,
177+ bool = std::is_same<T, int >::value,
178+ bool = std::is_same_v<std::remove_const_t <T>, int >,
179+ bool = std::is_same<std::remove_const_t <T>, int >::value,
180+ bool = std::is_same_v<typename std::remove_const<T>::type, int >,
181+ bool = std::is_same<typename std::remove_const<T>::type, int >::value,
182+ 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 ,
183+ 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 ,
184+ 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 >)>,
185+ typename = typename std::remove_const<T>::type,
186+ typename = std::remove_const_t <T>>
187+ void func (const T& param) {
188+ int array1[1 ];
189+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
190+
191+ T array2[2 ];
192+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
193+
194+ T value;
195+ }
196+
197+ // here, plenty of array type findings are expected for below template parameter declarations since array types get written explicitly
198+ template <typename T = int [],
199+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
200+ bool = std::is_same_v<T, int []>,
201+ // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
202+ bool = std::is_same<T, int [10 ]>::value,
203+ // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
204+ 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 ,
205+ // CHECK-MESSAGES: :[[@LINE-1]]:71: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
206+ // CHECK-MESSAGES: :[[@LINE-2]]:138: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
207+ typename = typename std::remove_const<int [10 ]>::type,
208+ // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
209+ typename = std::remove_const_t <int []>>
210+ // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
211+ void fun (const T& param) {
212+ int array3[3 ];
213+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
214+
215+ T array4[4 ];
216+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
217+
218+ T value;
219+ }
220+
221+ template <typename T>
222+ T some_constant{};
223+
224+ // explicit instantiation
225+ template
226+ int some_constant<int [5 ]>[5 ];
227+ // FIXME: why no diagnostics here?
228+
229+ // explicit specialization
230+ template <>
231+ int some_constant<int [7 ]>[7 ]{};
232+ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
233+ // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
234+
235+ void testArrayInTemplateType () {
236+ int t[10 ];
237+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
238+
239+ func (t);
240+ fun (t);
241+
242+ func<decltype (t)>({});
243+ fun<decltype (t)>({});
244+
245+ MyClassTemplate var1{t};
246+ MyClassTemplate<decltype (t)> var2{{}};
247+
248+ decltype (var1)::MyInnerClassTemplate var3{t};
249+ decltype (var1)::MyInnerClassTemplate<decltype (t)> var4{{}};
250+
251+ MyClassTemplate<decltype (t)>::MyInnerClassTemplate var5{t};
252+ MyClassTemplate<decltype (t)>::MyInnerClassTemplate<decltype (t)> var6{{}};
253+ }
0 commit comments