1// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s modernize-use-default-member-init %t -- -- -fexceptions
2// FIXME: Fix the checker to work in C++20 mode.
3
4struct S {
5};
6
7struct PositiveValueChar {
8 PositiveValueChar() : c0(), c1()/*, c2(), c3()*/ {}
9 // CHECK-FIXES: PositiveValueChar() {}
10 const char c0;
11 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use default member initializer for 'c0' [modernize-use-default-member-init]
12 // CHECK-FIXES: const char c0{};
13 wchar_t c1;
14 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer for 'c1'
15 // CHECK-FIXES: wchar_t c1{};
16 // FIXME: char16_t c2;
17 // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c2'
18 // C HECK-FIXES: char16_t c2{};
19 // FIXME: char32_t c3;
20 // C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c3'
21 // C HECK-FIXES: char32_t c3{};
22};
23
24struct PositiveChar {
25 PositiveChar() : d('a') {}
26 // CHECK-FIXES: PositiveChar() {}
27 char d;
28 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'd'
29 // CHECK-FIXES: char d{'a'};
30};
31
32struct PositiveValueInt {
33 PositiveValueInt() : i() {}
34 // CHECK-FIXES: PositiveValueInt() {}
35 const int i;
36 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use default member initializer for 'i'
37 // CHECK-FIXES: const int i{};
38};
39
40struct PositiveInt {
41 PositiveInt() : j(1) {}
42 // CHECK-FIXES: PositiveInt() {}
43 int j;
44 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
45 // CHECK-FIXES: int j{1};
46};
47
48struct PositiveNotDefaultInt {
49 PositiveNotDefaultInt(int) : i(7) {}
50 // CHECK-FIXES: PositiveNotDefaultInt(int) {}
51 int i;
52 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
53 // CHECK-FIXES: int i{7};
54};
55
56// We cannot reconcile these initializers.
57struct TwoConstructors {
58 TwoConstructors(int) : i(7) {}
59 TwoConstructors(int, int) : i(8) {}
60 int i;
61};
62
63struct TwoConstructorsTpl {
64 TwoConstructorsTpl() : i{7} {}
65 template <typename T> TwoConstructorsTpl(T, int) : i(8) {}
66 int i;
67};
68
69struct PositiveNotDefaultOOLInt {
70 PositiveNotDefaultOOLInt(int);
71 int i;
72 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
73 // CHECK-FIXES: int i{7};
74};
75
76PositiveNotDefaultOOLInt::PositiveNotDefaultOOLInt(int) : i(7) {}
77// CHECK-FIXES: PositiveNotDefaultOOLInt::PositiveNotDefaultOOLInt(int) {}
78
79struct PositiveNotDefaultOOLInt2 {
80 PositiveNotDefaultOOLInt2(int, int);
81 int i;
82 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
83 // CHECK-FIXES: int i{7};
84 int j;
85};
86
87PositiveNotDefaultOOLInt2::PositiveNotDefaultOOLInt2(int, int arg) : i(7), j(arg) {}
88// CHECK-FIXES: PositiveNotDefaultOOLInt2::PositiveNotDefaultOOLInt2(int, int arg) : j(arg) {}
89
90struct PositiveUnaryMinusInt {
91 PositiveUnaryMinusInt() : j(-1) {}
92 // CHECK-FIXES: PositiveUnaryMinusInt() {}
93 int j;
94 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
95 // CHECK-FIXES: int j{-1};
96};
97
98struct PositiveUnaryPlusInt {
99 PositiveUnaryPlusInt() : j(+1) {}
100 // CHECK-FIXES: PositiveUnaryPlusInt() {}
101 int j;
102 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
103 // CHECK-FIXES: int j{+1};
104};
105
106struct PositiveValueComplexInt {
107 PositiveValueComplexInt() : i() {}
108 // CHECK-FIXES: PositiveValueComplexInt() {}
109 _Complex int i;
110 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use default member initializer for 'i'
111 // CHECK-FIXES: _Complex int i{};
112};
113
114struct PositiveValueFloat {
115 PositiveValueFloat() : f() {}
116 // CHECK-FIXES: PositiveValueFloat() {}
117 float f;
118 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'f'
119 // CHECK-FIXES: float f{};
120};
121
122struct PositiveValueDouble {
123 PositiveValueDouble() : d() {}
124 // CHECK-FIXES: PositiveValueDouble() {}
125 double d;
126 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd'
127 // CHECK-FIXES: double d{};
128};
129
130struct PositiveDouble {
131 PositiveDouble() : f(2.5463e43) {}
132 // CHECK-FIXES: PositiveDouble() {}
133 double f;
134 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
135 // CHECK-FIXES: double f{2.5463e43};
136};
137
138struct PositiveValueComplexFloat {
139 PositiveValueComplexFloat() : f() {}
140 // CHECK-FIXES: PositiveValueComplexFloat() {}
141 _Complex float f;
142 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use default member initializer for 'f'
143 // CHECK-FIXES: _Complex float f{};
144};
145
146struct PositiveValueComplexDouble {
147 PositiveValueComplexDouble() : f() {}
148 // CHECK-FIXES: PositiveValueComplexDouble() {}
149 _Complex double f;
150 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use default member initializer for 'f'
151 // CHECK-FIXES: _Complex double f{};
152};
153
154struct PositiveUnaryMinusDouble {
155 PositiveUnaryMinusDouble() : f(-2.5463e43) {}
156 // CHECK-FIXES: PositiveUnaryMinusDouble() {}
157 double f;
158 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
159 // CHECK-FIXES: double f{-2.5463e43};
160};
161
162struct PositiveUnaryPlusDouble {
163 PositiveUnaryPlusDouble() : f(+2.5463e43) {}
164 // CHECK-FIXES: PositiveUnaryPlusDouble() {}
165 double f;
166 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
167 // CHECK-FIXES: double f{+2.5463e43};
168};
169
170struct PositiveValueBool {
171 PositiveValueBool() : b() {}
172 // CHECK-FIXES: PositiveValueBool() {}
173 bool b;
174 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b'
175 // CHECK-FIXES: bool b{};
176};
177
178struct PositiveBool {
179 PositiveBool() : a(true) {}
180 // CHECK-FIXES: PositiveBool() {}
181 bool a;
182 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a'
183 // CHECK-FIXES: bool a{true};
184};
185
186struct PositiveValuePointer {
187 PositiveValuePointer() : p() {}
188 // CHECK-FIXES: PositiveValuePointer() {}
189 int *p;
190 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p'
191 // CHECK-FIXES: int *p{};
192};
193
194struct PositiveNullPointer {
195 PositiveNullPointer() : q(nullptr) {}
196 // CHECK-FIXES: PositiveNullPointer() {}
197 int *q;
198 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q'
199 // CHECK-FIXES: int *q{nullptr};
200};
201
202enum Enum { Foo, Bar };
203struct PositiveEnum {
204 PositiveEnum() : e(Foo) {}
205 // CHECK-FIXES: PositiveEnum() {}
206 Enum e;
207 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
208 // CHECK-FIXES: Enum e{Foo};
209};
210
211struct PositiveValueEnum {
212 PositiveValueEnum() : e() {}
213 // CHECK-FIXES: PositiveValueEnum() {}
214 Enum e;
215 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
216 // CHECK-FIXES: Enum e{};
217};
218
219struct PositiveString {
220 PositiveString() : s("foo") {}
221 // CHECK-FIXES: PositiveString() {}
222 const char *s;
223 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use default member initializer for 's'
224 // CHECK-FIXES: const char *s{"foo"};
225};
226
227struct PositiveStruct {
228 PositiveStruct() : s(7) {}
229 // CHECK-FIXES: PositiveStruct() {}
230 struct {
231 int s;
232 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 's'
233 // CHECK-FIXES: int s{7};
234 };
235};
236
237template <typename T>
238struct NegativeTemplate {
239 NegativeTemplate() : t() {}
240 T t;
241};
242
243NegativeTemplate<int> nti;
244NegativeTemplate<double> ntd;
245
246struct NegativeDefaultMember {
247 NegativeDefaultMember() {}
248 int i = 2;
249};
250
251struct NegativeClass : S {
252 NegativeClass() : s() {}
253 S s;
254};
255
256struct NegativeBase : S {
257 NegativeBase() : S() {}
258};
259
260struct NegativeDefaultOtherMember{
261 NegativeDefaultOtherMember() : i(3) {}
262 int i = 4;
263};
264
265struct NegativeUnion {
266 NegativeUnion() : d(5.0) {}
267 union {
268 int i;
269 double d;
270 };
271};
272
273struct NegativeBitField
274{
275 NegativeBitField() : i(6) {}
276 int i : 5;
277};
278
279struct NegativeDefaultArg
280{
281 NegativeDefaultArg(int i = 4) : i(i) {}
282 int i;
283};
284
285struct ExistingChar {
286 ExistingChar(short) : e1(), e2{}, e3(), e4() {}
287 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
288 // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is redundant
289 // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is redundant
290 // CHECK-FIXES: ExistingChar(short) : e4() {}
291 ExistingChar(int) : e1(0), e2{0}, e3(0), e4(0) {}
292 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is redundant
293 // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant
294 // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is redundant
295 // CHECK-FIXES: ExistingChar(int) : e4(0) {}
296 ExistingChar(long) : e1('\0'), e2{'\0'}, e3('\0'), e4('\0') {}
297 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant
298 // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
299 // CHECK-MESSAGES: :[[@LINE-3]]:44: warning: member initializer for 'e3' is redundant
300 // CHECK-FIXES: ExistingChar(long) : e4('\0') {}
301 ExistingChar(char) : e1('a'), e2{'a'}, e3('a'), e4('a') {}
302 // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: member initializer for 'e4' is redundant
303 // CHECK-FIXES: ExistingChar(char) : e1('a'), e2{'a'}, e3('a') {}
304 char e1{};
305 char e2 = 0;
306 char e3 = '\0';
307 char e4 = 'a';
308};
309
310struct ExistingInt {
311 ExistingInt(short) : e1(), e2{}, e3(), e4(), e5(), e6() {}
312 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
313 // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant
314 // CHECK-FIXES: ExistingInt(short) : e3(), e4(), e5(), e6() {}
315 ExistingInt(int) : e1(0), e2{0}, e3(0), e4(0), e5(0), e6(0) {}
316 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: member initializer for 'e1' is redundant
317 // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: member initializer for 'e2' is redundant
318 // CHECK-FIXES: ExistingInt(int) : e3(0), e4(0), e5(0), e6(0) {}
319 ExistingInt(long) : e1(5), e2{5}, e3(5), e4(5), e5(5), e6(5) {}
320 // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: member initializer for 'e3' is redundant
321 // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: member initializer for 'e4' is redundant
322 // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: member initializer for 'e6' is redundant
323 // CHECK-FIXES: ExistingInt(long) : e1(5), e2{5}, e5(5) {}
324 ExistingInt(char) : e1(-5), e2{-5}, e3(-5), e4(-5), e5(-5), e6(-5) {}
325 // CHECK-MESSAGES: :[[@LINE-1]]:55: warning: member initializer for 'e5' is redundant
326 // CHECK-FIXES: ExistingInt(char) : e1(-5), e2{-5}, e3(-5), e4(-5), e6(-5) {}
327 int e1{};
328 int e2 = 0;
329 int e3 = {5};
330 int e4{5};
331 int e5 = -5;
332 int e6 = +5;
333};
334
335struct ExistingDouble {
336 ExistingDouble(short) : e1(), e2{}, e3(), e4(), e5() {}
337 // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant
338 // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
339 // CHECK-FIXES: ExistingDouble(short) : e3(), e4(), e5() {}
340 ExistingDouble(int) : e1(0.0), e2{0.0}, e3(0.0), e4(0.0), e5(0.0) {}
341 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
342 // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
343 // CHECK-FIXES: ExistingDouble(int) : e3(0.0), e4(0.0), e5(0.0) {}
344 ExistingDouble(long) : e1(5.0), e2{5.0}, e3(5.0), e4(5.0), e5(5.0) {}
345 // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: member initializer for 'e3' is redundant
346 // CHECK-MESSAGES: :[[@LINE-2]]:62: warning: member initializer for 'e5' is redundant
347 // CHECK-FIXES: ExistingDouble(long) : e1(5.0), e2{5.0}, e4(5.0) {}
348 ExistingDouble(char) : e1(-5.0), e2{-5.0}, e3(-5.0), e4(-5.0), e5(-5.0) {}
349 // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: member initializer for 'e4' is redundant
350 // CHECK-FIXES: ExistingDouble(char) : e1(-5.0), e2{-5.0}, e3(-5.0), e5(-5.0) {}
351 double e1{};
352 double e2 = 0.0;
353 double e3 = 5.0;
354 double e4{-5.0};
355 double e5 = +5.0;
356};
357
358struct ExistingBool {
359 ExistingBool(short) : e1(), e2{}, e3() {}
360 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
361 // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is redundant
362 // CHECK-FIXES: ExistingBool(short) : e3() {}
363 ExistingBool(int) : e1(false), e2{false}, e3(false) {}
364 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is redundant
365 // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
366 // CHECK-FIXES: ExistingBool(int) : e3(false) {}
367 ExistingBool(long) : e1(true), e2{true}, e3(true) {}
368 // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: member initializer for 'e3' is redundant
369 // CHECK-FIXES: ExistingBool(long) : e1(true), e2{true} {}
370 bool e1{};
371 bool e2 = false;
372 bool e3{true};
373};
374
375struct ExistingEnum {
376 ExistingEnum(short) : e1(Foo), e2{Foo} {}
377 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
378 // CHECK-FIXES: ExistingEnum(short) : e2{Foo} {}
379 ExistingEnum(int) : e1(Bar), e2{Bar} {}
380 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: member initializer for 'e2' is redundant
381 // CHECK-FIXES: ExistingEnum(int) : e1(Bar) {}
382 Enum e1 = Foo;
383 Enum e2{Bar};
384};
385
386struct ExistingPointer {
387 ExistingPointer(short) : e1(), e2{}, e3(), e4() {}
388 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: member initializer for 'e1' is redundant
389 // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
390 // CHECK-MESSAGES: :[[@LINE-3]]:40: warning: member initializer for 'e3' is redundant
391 // CHECK-FIXES: ExistingPointer(short) : e4() {}
392 ExistingPointer(int) : e1(0), e2{0}, e3(0), e4(&e1) {}
393 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: member initializer for 'e1' is redundant
394 // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
395 // CHECK-MESSAGES: :[[@LINE-3]]:40: warning: member initializer for 'e3' is redundant
396 // CHECK-FIXES: ExistingPointer(int) : e4(&e1) {}
397 ExistingPointer(long) : e1(nullptr), e2{nullptr}, e3(nullptr), e4(&e2) {}
398 // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant
399 // CHECK-MESSAGES: :[[@LINE-2]]:40: warning: member initializer for 'e2' is redundant
400 // CHECK-MESSAGES: :[[@LINE-3]]:53: warning: member initializer for 'e3' is redundant
401 // CHECK-FIXES: ExistingPointer(long) : e4(&e2) {}
402 int *e1{};
403 int *e2 = 0;
404 int *e3{nullptr};
405 int **e4 = &e1;
406};
407
408struct ExistingString {
409 ExistingString(short) : e1(), e2{}, e3(), e4() {}
410 // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
411 // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
412 // CHECK-FIXES: ExistingString(short) : e3(), e4() {}
413 ExistingString(int) : e1(0), e2{0}, e3(0), e4(0) {}
414 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
415 // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: member initializer for 'e2' is redundant
416 // CHECK-FIXES: ExistingString(int) : e3(0), e4(0) {}
417 ExistingString(long) : e1(nullptr), e2{nullptr}, e3(nullptr), e4(nullptr) {}
418 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: member initializer for 'e1' is redundant
419 // CHECK-MESSAGES: :[[@LINE-2]]:39: warning: member initializer for 'e2' is redundant
420 // CHECK-FIXES: ExistingString(long) : e3(nullptr), e4(nullptr) {}
421 ExistingString(char) : e1("foo"), e2{"foo"}, e3("foo"), e4("foo") {}
422 // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: member initializer for 'e3' is redundant
423 // CHECK-FIXES: ExistingString(char) : e1("foo"), e2{"foo"}, e4("foo") {}
424 const char *e1{};
425 const char *e2 = nullptr;
426 const char *e3 = "foo";
427 const char *e4 = "bar";
428};
429
430struct UnionExisting {
431 UnionExisting() : e(5.0) {}
432 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: member initializer for 'e' is redundant
433 // CHECK-FIXES: UnionExisting() {}
434 union {
435 int i;
436 double e = 5.0;
437 };
438};
439
440template <typename T>
441struct NegativeTemplateExisting {
442 NegativeTemplateExisting(int) : t(0) {}
443 T t{};
444};
445
446NegativeTemplateExisting<int> ntei(0);
447NegativeTemplateExisting<double> nted(0);
448
449// This resulted in a warning by default.
450#define MACRO() \
451 struct MacroS { \
452 void *P; \
453 MacroS() : P(nullptr) {} \
454 };
455
456MACRO();
457
458
459class FunctionTryBlock {
460public:
461 FunctionTryBlock() try : i(5), k(8) {}
462 // CHECK-FIXES: FunctionTryBlock() try {}
463 catch (...) {}
464
465private:
466 int i, k;
467 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i' [modernize-use-default-member-init]
468 // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: use default member initializer for 'k' [modernize-use-default-member-init]
469 // CHECK-FIXES: int i{5}, k{8};
470};
471
472struct PR45363 {
473 // Ensure no warning is emitted here
474 PR45363(int i = 0) : m_i{i} {}
475 int m_i;
476};
477
478struct EmptyBracedIntDefault {
479 EmptyBracedIntDefault() : m_i{} {}
480 int m_i;
481 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'm_i' [modernize-use-default-member-init]
482 // CHECK-FIXES: {{^ }}EmptyBracedIntDefault() {}
483 // CHECK-FIXES-NEXT: {{^ }}int m_i{};
484};
485
486namespace PR63285 {
487
488class ArrayValueInit {
489 ArrayValueInit() : m_array() {}
490 double m_array[1];
491 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init]
492 // CHECK-FIXES: {{^ }}ArrayValueInit() {}
493 // CHECK-FIXES-NEXT: {{^ }}double m_array[1]{};
494};
495
496class ArrayBraceInit {
497 ArrayBraceInit() : m_array{} {}
498 double m_array[1];
499 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init]
500 // CHECK-FIXES: {{^ }}ArrayBraceInit() {}
501 // CHECK-FIXES-NEXT: {{^ }}double m_array[1]{};
502};
503
504class ArrayBraceInitWithValue {
505 ArrayBraceInitWithValue() : m_array{3.14} {}
506 double m_array[1];
507 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init]
508 // CHECK-FIXES: {{^ }}ArrayBraceInitWithValue() {}
509 // CHECK-FIXES-NEXT: {{^ }}double m_array[1]{3.14};
510};
511
512class ArrayBraceInitMultipleValues {
513 ArrayBraceInitMultipleValues() : m_array{1.0, 2.0, 3.0} {}
514 double m_array[3];
515 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init]
516 // CHECK-FIXES: {{^ }}ArrayBraceInitMultipleValues() {}
517 // CHECK-FIXES-NEXT: {{^ }}double m_array[3]{1.0, 2.0, 3.0};
518};
519
520} // namespace PR63285
521

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp