1 // RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- \ 2 // RUN: -config="{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: 1}]}" -- -std=c++11 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 = '\0'; 13 wchar_t c1; 14 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer for 'c1' 15 // CHECK-FIXES: wchar_t c1 = L'\0'; 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 = u'\0'; 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 = U'\0'; 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 = 0; 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 PositiveUnaryMinusInt { PositiveUnaryMinusIntPositiveUnaryMinusInt49 PositiveUnaryMinusInt() : j(-1) {} 50 // CHECK-FIXES: PositiveUnaryMinusInt() {} 51 int j; 52 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j' 53 // CHECK-FIXES: int j = -1; 54 }; 55 56 struct PositiveUnaryPlusInt { PositiveUnaryPlusIntPositiveUnaryPlusInt57 PositiveUnaryPlusInt() : j(+1) {} 58 // CHECK-FIXES: PositiveUnaryPlusInt() {} 59 int j; 60 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j' 61 // CHECK-FIXES: int j = +1; 62 }; 63 64 struct PositiveValueComplexInt { PositiveValueComplexIntPositiveValueComplexInt65 PositiveValueComplexInt() : i() {} 66 // CHECK-FIXES: PositiveValueComplexInt() {} 67 _Complex int i; 68 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use default member initializer for 'i' 69 // CHECK-FIXES: _Complex int i = 0; 70 }; 71 72 struct PositiveValueFloat { PositiveValueFloatPositiveValueFloat73 PositiveValueFloat() : f() {} 74 // CHECK-FIXES: PositiveValueFloat() {} 75 float f; 76 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'f' 77 // CHECK-FIXES: float f = 0.0f; 78 }; 79 80 struct PositiveValueDouble { PositiveValueDoublePositiveValueDouble81 PositiveValueDouble() : d() {} 82 // CHECK-FIXES: PositiveValueDouble() {} 83 double d; 84 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd' 85 // CHECK-FIXES: double d = 0.0; 86 }; 87 88 struct PositiveDouble { PositiveDoublePositiveDouble89 PositiveDouble() : f(2.5463e43) {} 90 // CHECK-FIXES: PositiveDouble() {} 91 double f; 92 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f' 93 // CHECK-FIXES: double f = 2.5463e43; 94 }; 95 96 struct PositiveValueComplexFloat { PositiveValueComplexFloatPositiveValueComplexFloat97 PositiveValueComplexFloat() : f() {} 98 // CHECK-FIXES: PositiveValueComplexFloat() {} 99 _Complex float f; 100 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use default member initializer for 'f' 101 // CHECK-FIXES: _Complex float f = 0.0f; 102 }; 103 104 struct PositiveValueComplexDouble { PositiveValueComplexDoublePositiveValueComplexDouble105 PositiveValueComplexDouble() : f() {} 106 // CHECK-FIXES: PositiveValueComplexDouble() {} 107 _Complex double f; 108 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use default member initializer for 'f' 109 // CHECK-FIXES: _Complex double f = 0.0; 110 }; 111 112 struct PositiveUnaryMinusDouble { PositiveUnaryMinusDoublePositiveUnaryMinusDouble113 PositiveUnaryMinusDouble() : f(-2.5463e43) {} 114 // CHECK-FIXES: PositiveUnaryMinusDouble() {} 115 double f; 116 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f' 117 // CHECK-FIXES: double f = -2.5463e43; 118 }; 119 120 struct PositiveUnaryPlusDouble { PositiveUnaryPlusDoublePositiveUnaryPlusDouble121 PositiveUnaryPlusDouble() : f(+2.5463e43) {} 122 // CHECK-FIXES: PositiveUnaryPlusDouble() {} 123 double f; 124 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f' 125 // CHECK-FIXES: double f = +2.5463e43; 126 }; 127 128 struct PositiveValueBool { PositiveValueBoolPositiveValueBool129 PositiveValueBool() : b() {} 130 // CHECK-FIXES: PositiveValueBool() {} 131 bool b; 132 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b' 133 // CHECK-FIXES: bool b = false; 134 }; 135 136 struct PositiveBool { PositiveBoolPositiveBool137 PositiveBool() : a(true) {} 138 // CHECK-FIXES: PositiveBool() {} 139 bool a; 140 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a' 141 // CHECK-FIXES: bool a = true; 142 }; 143 144 struct PositiveValuePointer { PositiveValuePointerPositiveValuePointer145 PositiveValuePointer() : p() {} 146 // CHECK-FIXES: PositiveValuePointer() {} 147 int *p; 148 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p' 149 // CHECK-FIXES: int *p = nullptr; 150 }; 151 152 struct PositiveNullPointer { PositiveNullPointerPositiveNullPointer153 PositiveNullPointer() : q(nullptr) {} 154 // CHECK-FIXES: PositiveNullPointer() {} 155 int *q; 156 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q' 157 // CHECK-FIXES: int *q = nullptr; 158 }; 159 160 enum Enum { Foo }; 161 struct PositiveEnum { PositiveEnumPositiveEnum162 PositiveEnum() : e(Foo) {} 163 // CHECK-FIXES: PositiveEnum() {} 164 Enum e; 165 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e' 166 // CHECK-FIXES: Enum e = Foo; 167 }; 168 169 struct PositiveString { PositiveStringPositiveString170 PositiveString() : s("foo") {} 171 // CHECK-FIXES: PositiveString() {} 172 const char *s; 173 // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use default member initializer for 's' 174 // CHECK-FIXES: const char *s = "foo"; 175 }; 176 177 template <typename T> 178 struct NegativeTemplate { NegativeTemplateNegativeTemplate179 NegativeTemplate() : t() {} 180 T t; 181 }; 182 183 NegativeTemplate<int> nti; 184 NegativeTemplate<double> ntd; 185