modernize-use-default-member-init-assignment.cpp
5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- \
// RUN: -config="{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: 1}]}"
struct S {
};
struct PositiveValueChar {
PositiveValueChar() : c0(), c1()/*, c2(), c3()*/ {}
// CHECK-FIXES: PositiveValueChar() {}
const char c0;
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use default member initializer for 'c0' [modernize-use-default-member-init]
// CHECK-FIXES: const char c0 = '\0';
wchar_t c1;
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use default member initializer for 'c1'
// CHECK-FIXES: wchar_t c1 = L'\0';
// FIXME: char16_t c2;
// C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c2'
// C HECK-FIXES: char16_t c2 = u'\0';
// FIXME: char32_t c3;
// C HECK-MESSAGES: :[[@LINE-1]]:12: warning: use default member initializer for 'c3'
// C HECK-FIXES: char32_t c3 = U'\0';
};
struct PositiveChar {
PositiveChar() : d('a') {}
// CHECK-FIXES: PositiveChar() {}
char d;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'd'
// CHECK-FIXES: char d = 'a';
};
struct PositiveValueInt {
PositiveValueInt() : i() {}
// CHECK-FIXES: PositiveValueInt() {}
const int i;
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use default member initializer for 'i'
// CHECK-FIXES: const int i = 0;
};
struct PositiveInt {
PositiveInt() : j(1) {}
// CHECK-FIXES: PositiveInt() {}
int j;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
// CHECK-FIXES: int j = 1;
};
struct PositiveUnaryMinusInt {
PositiveUnaryMinusInt() : j(-1) {}
// CHECK-FIXES: PositiveUnaryMinusInt() {}
int j;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
// CHECK-FIXES: int j = -1;
};
struct PositiveUnaryPlusInt {
PositiveUnaryPlusInt() : j(+1) {}
// CHECK-FIXES: PositiveUnaryPlusInt() {}
int j;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
// CHECK-FIXES: int j = +1;
};
struct PositiveValueComplexInt {
PositiveValueComplexInt() : i() {}
// CHECK-FIXES: PositiveValueComplexInt() {}
_Complex int i;
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use default member initializer for 'i'
// CHECK-FIXES: _Complex int i = 0;
};
struct PositiveValueFloat {
PositiveValueFloat() : f() {}
// CHECK-FIXES: PositiveValueFloat() {}
float f;
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'f'
// CHECK-FIXES: float f = 0.0f;
};
struct PositiveValueDouble {
PositiveValueDouble() : d() {}
// CHECK-FIXES: PositiveValueDouble() {}
double d;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd'
// CHECK-FIXES: double d = 0.0;
};
struct PositiveDouble {
PositiveDouble() : f(2.5463e43) {}
// CHECK-FIXES: PositiveDouble() {}
double f;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
// CHECK-FIXES: double f = 2.5463e43;
};
struct PositiveValueComplexFloat {
PositiveValueComplexFloat() : f() {}
// CHECK-FIXES: PositiveValueComplexFloat() {}
_Complex float f;
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use default member initializer for 'f'
// CHECK-FIXES: _Complex float f = 0.0f;
};
struct PositiveValueComplexDouble {
PositiveValueComplexDouble() : f() {}
// CHECK-FIXES: PositiveValueComplexDouble() {}
_Complex double f;
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use default member initializer for 'f'
// CHECK-FIXES: _Complex double f = 0.0;
};
struct PositiveUnaryMinusDouble {
PositiveUnaryMinusDouble() : f(-2.5463e43) {}
// CHECK-FIXES: PositiveUnaryMinusDouble() {}
double f;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
// CHECK-FIXES: double f = -2.5463e43;
};
struct PositiveUnaryPlusDouble {
PositiveUnaryPlusDouble() : f(+2.5463e43) {}
// CHECK-FIXES: PositiveUnaryPlusDouble() {}
double f;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
// CHECK-FIXES: double f = +2.5463e43;
};
struct PositiveValueBool {
PositiveValueBool() : b() {}
// CHECK-FIXES: PositiveValueBool() {}
bool b;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b'
// CHECK-FIXES: bool b = false;
};
struct PositiveBool {
PositiveBool() : a(true) {}
// CHECK-FIXES: PositiveBool() {}
bool a;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a'
// CHECK-FIXES: bool a = true;
};
struct PositiveValuePointer {
PositiveValuePointer() : p() {}
// CHECK-FIXES: PositiveValuePointer() {}
int *p;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p'
// CHECK-FIXES: int *p = nullptr;
};
struct PositiveNullPointer {
PositiveNullPointer() : q(nullptr) {}
// CHECK-FIXES: PositiveNullPointer() {}
int *q;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q'
// CHECK-FIXES: int *q = nullptr;
};
enum Enum { Foo };
struct PositiveEnum {
PositiveEnum() : e(Foo) {}
// CHECK-FIXES: PositiveEnum() {}
Enum e;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
// CHECK-FIXES: Enum e = Foo;
};
struct PositiveValueEnum {
PositiveValueEnum() : e() {}
// CHECK-FIXES: PositiveValueEnum() {}
Enum e;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
// CHECK-FIXES: Enum e{};
};
struct PositiveString {
PositiveString() : s("foo") {}
// CHECK-FIXES: PositiveString() {}
const char *s;
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use default member initializer for 's'
// CHECK-FIXES: const char *s = "foo";
};
template <typename T>
struct NegativeTemplate {
NegativeTemplate() : t() {}
T t;
};
NegativeTemplate<int> nti;
NegativeTemplate<double> ntd;