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 
4 struct S {
5 };
6 
7 struct PositiveValueChar {
PositiveValueCharPositiveValueChar8   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 
24 struct PositiveChar {
PositiveCharPositiveChar25   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 
32 struct PositiveValueInt {
PositiveValueIntPositiveValueInt33   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 
40 struct PositiveInt {
PositiveIntPositiveInt41   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 
48 struct PositiveNotDefaultInt {
PositiveNotDefaultIntPositiveNotDefaultInt49   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.
57 struct TwoConstructors {
TwoConstructorsTwoConstructors58     TwoConstructors(int) : i(7) {}
TwoConstructorsTwoConstructors59     TwoConstructors(int, int) : i(8) {}
60     int i;
61 };
62 
63 struct PositiveNotDefaultOOLInt {
64   PositiveNotDefaultOOLInt(int);
65   int i;
66   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
67   // CHECK-FIXES: int i{7};
68 };
69 
PositiveNotDefaultOOLInt(int)70 PositiveNotDefaultOOLInt::PositiveNotDefaultOOLInt(int) : i(7) {}
71 // CHECK-FIXES: PositiveNotDefaultOOLInt::PositiveNotDefaultOOLInt(int)  {}
72 
73 struct PositiveNotDefaultOOLInt2 {
74   PositiveNotDefaultOOLInt2(int, int);
75   int i;
76   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
77   // CHECK-FIXES: int i{7};
78   int j;
79 };
80 
PositiveNotDefaultOOLInt2(int,int arg)81 PositiveNotDefaultOOLInt2::PositiveNotDefaultOOLInt2(int, int arg) : i(7), j(arg) {}
82 // CHECK-FIXES: PositiveNotDefaultOOLInt2::PositiveNotDefaultOOLInt2(int, int arg) :  j(arg) {}
83 
84 struct PositiveUnaryMinusInt {
PositiveUnaryMinusIntPositiveUnaryMinusInt85   PositiveUnaryMinusInt() : j(-1) {}
86   // CHECK-FIXES: PositiveUnaryMinusInt()  {}
87   int j;
88   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
89   // CHECK-FIXES: int j{-1};
90 };
91 
92 struct PositiveUnaryPlusInt {
PositiveUnaryPlusIntPositiveUnaryPlusInt93   PositiveUnaryPlusInt() : j(+1) {}
94   // CHECK-FIXES: PositiveUnaryPlusInt()  {}
95   int j;
96   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
97   // CHECK-FIXES: int j{+1};
98 };
99 
100 struct PositiveValueComplexInt {
PositiveValueComplexIntPositiveValueComplexInt101   PositiveValueComplexInt() : i() {}
102   // CHECK-FIXES: PositiveValueComplexInt()  {}
103   _Complex int i;
104   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use default member initializer for 'i'
105   // CHECK-FIXES: _Complex int i{};
106 };
107 
108 struct PositiveValueFloat {
PositiveValueFloatPositiveValueFloat109   PositiveValueFloat() : f() {}
110   // CHECK-FIXES: PositiveValueFloat()  {}
111   float f;
112   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'f'
113   // CHECK-FIXES: float f{};
114 };
115 
116 struct PositiveValueDouble {
PositiveValueDoublePositiveValueDouble117   PositiveValueDouble() : d() {}
118   // CHECK-FIXES: PositiveValueDouble()  {}
119   double d;
120   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd'
121   // CHECK-FIXES: double d{};
122 };
123 
124 struct PositiveDouble {
PositiveDoublePositiveDouble125   PositiveDouble() : f(2.5463e43) {}
126   // CHECK-FIXES: PositiveDouble()  {}
127   double f;
128   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
129   // CHECK-FIXES: double f{2.5463e43};
130 };
131 
132 struct PositiveValueComplexFloat {
PositiveValueComplexFloatPositiveValueComplexFloat133   PositiveValueComplexFloat() : f() {}
134   // CHECK-FIXES: PositiveValueComplexFloat()  {}
135   _Complex float f;
136   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use default member initializer for 'f'
137   // CHECK-FIXES: _Complex float f{};
138 };
139 
140 struct PositiveValueComplexDouble {
PositiveValueComplexDoublePositiveValueComplexDouble141   PositiveValueComplexDouble() : f() {}
142   // CHECK-FIXES: PositiveValueComplexDouble()  {}
143   _Complex double f;
144   // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use default member initializer for 'f'
145   // CHECK-FIXES: _Complex double f{};
146 };
147 
148 struct PositiveUnaryMinusDouble {
PositiveUnaryMinusDoublePositiveUnaryMinusDouble149   PositiveUnaryMinusDouble() : f(-2.5463e43) {}
150   // CHECK-FIXES: PositiveUnaryMinusDouble()  {}
151   double f;
152   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
153   // CHECK-FIXES: double f{-2.5463e43};
154 };
155 
156 struct PositiveUnaryPlusDouble {
PositiveUnaryPlusDoublePositiveUnaryPlusDouble157   PositiveUnaryPlusDouble() : f(+2.5463e43) {}
158   // CHECK-FIXES: PositiveUnaryPlusDouble()  {}
159   double f;
160   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
161   // CHECK-FIXES: double f{+2.5463e43};
162 };
163 
164 struct PositiveValueBool {
PositiveValueBoolPositiveValueBool165   PositiveValueBool() : b() {}
166   // CHECK-FIXES: PositiveValueBool()  {}
167   bool b;
168   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b'
169   // CHECK-FIXES: bool b{};
170 };
171 
172 struct PositiveBool {
PositiveBoolPositiveBool173   PositiveBool() : a(true) {}
174   // CHECK-FIXES: PositiveBool()  {}
175   bool a;
176   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a'
177   // CHECK-FIXES: bool a{true};
178 };
179 
180 struct PositiveValuePointer {
PositiveValuePointerPositiveValuePointer181   PositiveValuePointer() : p() {}
182   // CHECK-FIXES: PositiveValuePointer()  {}
183   int *p;
184   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p'
185   // CHECK-FIXES: int *p{};
186 };
187 
188 struct PositiveNullPointer {
PositiveNullPointerPositiveNullPointer189   PositiveNullPointer() : q(nullptr) {}
190   // CHECK-FIXES: PositiveNullPointer()  {}
191   int *q;
192   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q'
193   // CHECK-FIXES: int *q{nullptr};
194 };
195 
196 enum Enum { Foo, Bar };
197 struct PositiveEnum {
PositiveEnumPositiveEnum198   PositiveEnum() : e(Foo) {}
199   // CHECK-FIXES: PositiveEnum()  {}
200   Enum e;
201   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
202   // CHECK-FIXES: Enum e{Foo};
203 };
204 
205 struct PositiveValueEnum {
PositiveValueEnumPositiveValueEnum206   PositiveValueEnum() : e() {}
207   // CHECK-FIXES: PositiveValueEnum()  {}
208   Enum e;
209   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
210   // CHECK-FIXES: Enum e{};
211 };
212 
213 struct PositiveString {
PositiveStringPositiveString214   PositiveString() : s("foo") {}
215   // CHECK-FIXES: PositiveString()  {}
216   const char *s;
217   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use default member initializer for 's'
218   // CHECK-FIXES: const char *s{"foo"};
219 };
220 
221 struct PositiveStruct {
PositiveStructPositiveStruct222   PositiveStruct() : s(7) {}
223   // CHECK-FIXES: PositiveStruct()  {}
224   struct {
225     int s;
226     // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 's'
227     // CHECK-FIXES: int s{7};
228   };
229 };
230 
231 template <typename T>
232 struct NegativeTemplate {
NegativeTemplateNegativeTemplate233     NegativeTemplate() : t() {}
234     T t;
235 };
236 
237 NegativeTemplate<int> nti;
238 NegativeTemplate<double> ntd;
239 
240 struct NegativeDefaultMember {
NegativeDefaultMemberNegativeDefaultMember241   NegativeDefaultMember() {}
242   int i = 2;
243 };
244 
245 struct NegativeClass : S {
NegativeClassNegativeClass246   NegativeClass() : s() {}
247   S s;
248 };
249 
250 struct NegativeBase : S {
NegativeBaseNegativeBase251   NegativeBase() : S() {}
252 };
253 
254 struct NegativeDefaultOtherMember{
NegativeDefaultOtherMemberNegativeDefaultOtherMember255   NegativeDefaultOtherMember() : i(3) {}
256   int i = 4;
257 };
258 
259 struct NegativeUnion {
NegativeUnionNegativeUnion260   NegativeUnion() : d(5.0) {}
261   union {
262     int i;
263     double d;
264   };
265 };
266 
267 struct NegativeBitField
268 {
NegativeBitFieldNegativeBitField269   NegativeBitField() : i(6) {}
270   int i : 5;
271 };
272 
273 struct NegativeDefaultArg
274 {
NegativeDefaultArgNegativeDefaultArg275   NegativeDefaultArg(int i = 4) : i(i) {}
276   int i;
277 };
278 
279 struct ExistingChar {
ExistingCharExistingChar280   ExistingChar(short) : e1(), e2{}, e3(), e4() {}
281   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
282   // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is redundant
283   // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is redundant
284   // CHECK-FIXES: ExistingChar(short) :  e4() {}
ExistingCharExistingChar285   ExistingChar(int) : e1(0), e2{0}, e3(0), e4(0) {}
286   // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is redundant
287   // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant
288   // CHECK-MESSAGES: :[[@LINE-3]]:37: warning: member initializer for 'e3' is redundant
289   // CHECK-FIXES: ExistingChar(int) :  e4(0) {}
ExistingCharExistingChar290   ExistingChar(long) : e1('\0'), e2{'\0'}, e3('\0'), e4('\0') {}
291   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant
292   // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
293   // CHECK-MESSAGES: :[[@LINE-3]]:44: warning: member initializer for 'e3' is redundant
294   // CHECK-FIXES: ExistingChar(long) :  e4('\0') {}
ExistingCharExistingChar295   ExistingChar(char) : e1('a'), e2{'a'}, e3('a'), e4('a') {}
296   // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: member initializer for 'e4' is redundant
297   // CHECK-FIXES: ExistingChar(char) : e1('a'), e2{'a'}, e3('a') {}
298   char e1{};
299   char e2 = 0;
300   char e3 = '\0';
301   char e4 = 'a';
302 };
303 
304 struct ExistingInt {
ExistingIntExistingInt305   ExistingInt(short) : e1(), e2{}, e3(), e4(), e5(), e6() {}
306   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
307   // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant
308   // CHECK-FIXES: ExistingInt(short) :  e3(), e4(), e5(), e6() {}
ExistingIntExistingInt309   ExistingInt(int) : e1(0), e2{0}, e3(0), e4(0), e5(0), e6(0) {}
310   // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: member initializer for 'e1' is redundant
311   // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: member initializer for 'e2' is redundant
312   // CHECK-FIXES: ExistingInt(int) :  e3(0), e4(0), e5(0), e6(0) {}
ExistingIntExistingInt313   ExistingInt(long) : e1(5), e2{5}, e3(5), e4(5), e5(5), e6(5) {}
314   // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: member initializer for 'e3' is redundant
315   // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: member initializer for 'e4' is redundant
316   // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: member initializer for 'e6' is redundant
317   // CHECK-FIXES: ExistingInt(long) : e1(5), e2{5},  e5(5) {}
ExistingIntExistingInt318   ExistingInt(char) : e1(-5), e2{-5}, e3(-5), e4(-5), e5(-5), e6(-5) {}
319   // CHECK-MESSAGES: :[[@LINE-1]]:55: warning: member initializer for 'e5' is redundant
320   // CHECK-FIXES: ExistingInt(char) : e1(-5), e2{-5}, e3(-5), e4(-5),  e6(-5) {}
321   int e1{};
322   int e2 = 0;
323   int e3 = {5};
324   int e4{5};
325   int e5 = -5;
326   int e6 = +5;
327 };
328 
329 struct ExistingDouble {
ExistingDoubleExistingDouble330   ExistingDouble(short) : e1(), e2{}, e3(), e4(), e5() {}
331   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant
332   // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
333   // CHECK-FIXES: ExistingDouble(short) :  e3(), e4(), e5() {}
ExistingDoubleExistingDouble334   ExistingDouble(int) : e1(0.0), e2{0.0}, e3(0.0), e4(0.0), e5(0.0) {}
335   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
336   // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
337   // CHECK-FIXES: ExistingDouble(int) :  e3(0.0), e4(0.0), e5(0.0) {}
ExistingDoubleExistingDouble338   ExistingDouble(long) : e1(5.0), e2{5.0}, e3(5.0), e4(5.0), e5(5.0) {}
339   // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: member initializer for 'e3' is redundant
340   // CHECK-MESSAGES: :[[@LINE-2]]:62: warning: member initializer for 'e5' is redundant
341   // CHECK-FIXES: ExistingDouble(long) : e1(5.0), e2{5.0},  e4(5.0) {}
ExistingDoubleExistingDouble342   ExistingDouble(char) : e1(-5.0), e2{-5.0}, e3(-5.0), e4(-5.0), e5(-5.0) {}
343   // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: member initializer for 'e4' is redundant
344   // CHECK-FIXES: ExistingDouble(char) : e1(-5.0), e2{-5.0}, e3(-5.0),  e5(-5.0) {}
345   double e1{};
346   double e2 = 0.0;
347   double e3 = 5.0;
348   double e4{-5.0};
349   double e5 = +5.0;
350 };
351 
352 struct ExistingBool {
ExistingBoolExistingBool353   ExistingBool(short) : e1(), e2{}, e3() {}
354   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
355   // CHECK-MESSAGES: :[[@LINE-2]]:31: warning: member initializer for 'e2' is redundant
356   // CHECK-FIXES: ExistingBool(short) :  e3() {}
ExistingBoolExistingBool357   ExistingBool(int) : e1(false), e2{false}, e3(false) {}
358   // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: member initializer for 'e1' is redundant
359   // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
360   // CHECK-FIXES: ExistingBool(int) :  e3(false) {}
ExistingBoolExistingBool361   ExistingBool(long) : e1(true), e2{true}, e3(true) {}
362   // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: member initializer for 'e3' is redundant
363   // CHECK-FIXES: ExistingBool(long) : e1(true), e2{true} {}
364   bool e1{};
365   bool e2 = false;
366   bool e3{true};
367 };
368 
369 struct ExistingEnum {
ExistingEnumExistingEnum370   ExistingEnum(short) : e1(Foo), e2{Foo} {}
371   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
372   // CHECK-FIXES: ExistingEnum(short) :  e2{Foo} {}
ExistingEnumExistingEnum373   ExistingEnum(int) : e1(Bar), e2{Bar} {}
374   // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: member initializer for 'e2' is redundant
375   // CHECK-FIXES: ExistingEnum(int) : e1(Bar) {}
376   Enum e1 = Foo;
377   Enum e2{Bar};
378 };
379 
380 struct ExistingPointer {
ExistingPointerExistingPointer381   ExistingPointer(short) : e1(), e2{}, e3(), e4() {}
382   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: member initializer for 'e1' is redundant
383   // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: member initializer for 'e2' is redundant
384   // CHECK-MESSAGES: :[[@LINE-3]]:40: warning: member initializer for 'e3' is redundant
385   // CHECK-FIXES: ExistingPointer(short) :  e4() {}
ExistingPointerExistingPointer386   ExistingPointer(int) : e1(0), e2{0}, e3(0), e4(&e1) {}
387   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: member initializer for 'e1' is redundant
388   // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
389   // CHECK-MESSAGES: :[[@LINE-3]]:40: warning: member initializer for 'e3' is redundant
390   // CHECK-FIXES: ExistingPointer(int) :  e4(&e1) {}
ExistingPointerExistingPointer391   ExistingPointer(long) : e1(nullptr), e2{nullptr}, e3(nullptr), e4(&e2) {}
392   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant
393   // CHECK-MESSAGES: :[[@LINE-2]]:40: warning: member initializer for 'e2' is redundant
394   // CHECK-MESSAGES: :[[@LINE-3]]:53: warning: member initializer for 'e3' is redundant
395   // CHECK-FIXES: ExistingPointer(long) :  e4(&e2) {}
396   int *e1{};
397   int *e2 = 0;
398   int *e3{nullptr};
399   int **e4 = &e1;
400 };
401 
402 struct ExistingString {
ExistingStringExistingString403   ExistingString(short) : e1(), e2{}, e3(), e4() {}
404   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
405   // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: member initializer for 'e2' is redundant
406   // CHECK-FIXES: ExistingString(short) :  e3(), e4() {}
ExistingStringExistingString407   ExistingString(int) : e1(0), e2{0}, e3(0), e4(0) {}
408   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant
409   // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: member initializer for 'e2' is redundant
410   // CHECK-FIXES: ExistingString(int) :  e3(0), e4(0) {}
ExistingStringExistingString411   ExistingString(long) : e1(nullptr), e2{nullptr}, e3(nullptr), e4(nullptr) {}
412   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: member initializer for 'e1' is redundant
413   // CHECK-MESSAGES: :[[@LINE-2]]:39: warning: member initializer for 'e2' is redundant
414   // CHECK-FIXES: ExistingString(long) :  e3(nullptr), e4(nullptr) {}
ExistingStringExistingString415   ExistingString(char) : e1("foo"), e2{"foo"}, e3("foo"), e4("foo") {}
416   // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: member initializer for 'e3' is redundant
417   // CHECK-FIXES: ExistingString(char) : e1("foo"), e2{"foo"},  e4("foo") {}
418   const char *e1{};
419   const char *e2 = nullptr;
420   const char *e3 = "foo";
421   const char *e4 = "bar";
422 };
423 
424 struct UnionExisting {
UnionExistingUnionExisting425   UnionExisting() : e(5.0) {}
426   // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: member initializer for 'e' is redundant
427   // CHECK-FIXES: UnionExisting()  {}
428   union {
429     int i;
430     double e = 5.0;
431   };
432 };
433 
434 template <typename T>
435 struct NegativeTemplateExisting {
NegativeTemplateExistingNegativeTemplateExisting436   NegativeTemplateExisting(int) : t(0) {}
437   T t{};
438 };
439 
440 NegativeTemplateExisting<int> ntei(0);
441 NegativeTemplateExisting<double> nted(0);
442 
443 // This resulted in a warning by default.
444 #define MACRO() \
445   struct MacroS { \
446     void *P; \
447     MacroS() : P(nullptr) {} \
448   };
449 
450 MACRO();
451 
452 
453 class FunctionTryBlock {
454 public:
FunctionTryBlock()455   FunctionTryBlock() try : i(5), k(8) {}
456   // CHECK-FIXES: FunctionTryBlock() try  {}
457   catch (...) {}
458 
459 private:
460   int i, k;
461   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i' [modernize-use-default-member-init]
462   // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: use default member initializer for 'k' [modernize-use-default-member-init]
463   // CHECK-FIXES: int i{5}, k{8};
464 };
465 
466 struct PR45363 {
467   // Ensure no warning is emitted here
PR45363PR45363468   PR45363(int i = 0) : m_i{i} {}
469   int m_i;
470 };
471 
472 struct EmptyBracedIntDefault {
EmptyBracedIntDefaultEmptyBracedIntDefault473   EmptyBracedIntDefault() : m_i{} {}
474   int m_i;
475   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'm_i' [modernize-use-default-member-init]
476   // CHECK-FIXES:      {{^  }}EmptyBracedIntDefault()  {}
477   // CHECK-FIXES-NEXT: {{^  }}int m_i{};
478 };
479