@@ -35,23 +35,23 @@ AST_MATCHER(clang::VarDecl, isDirectInitialization) {
35
35
36
36
} // namespace
37
37
38
- RewriteRuleWith<std::string> StringviewNullptrCheckImpl () {
39
- auto construction_warning =
38
+ RewriteRuleWith<std::string> stringviewNullptrCheckImpl () {
39
+ auto ConstructionWarning =
40
40
cat (" constructing basic_string_view from null is undefined; replace with "
41
41
" the default constructor" );
42
- auto static_cast_warning =
42
+ auto StaticCastWarning =
43
43
cat (" casting to basic_string_view from null is undefined; replace with "
44
44
" the empty string" );
45
- auto argument_construction_warning =
45
+ auto ArgumentConstructionWarning =
46
46
cat (" passing null as basic_string_view is undefined; replace with the "
47
47
" empty string" );
48
- auto assignment_warning =
48
+ auto AssignmentWarning =
49
49
cat (" assignment to basic_string_view from null is undefined; replace "
50
50
" with the default constructor" );
51
- auto relative_comparison_warning =
51
+ auto RelativeComparisonWarning =
52
52
cat (" comparing basic_string_view to null is undefined; replace with the "
53
53
" empty string" );
54
- auto equality_comparison_warning =
54
+ auto EqualityComparisonWarning =
55
55
cat (" comparing basic_string_view to null is undefined; replace with the "
56
56
" emptiness query" );
57
57
@@ -84,7 +84,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
84
84
auto HandleTemporaryCXXFunctionalCastExpr =
85
85
makeRule (cxxFunctionalCastExpr (hasSourceExpression (
86
86
BasicStringViewConstructingFromNullExpr)),
87
- remove (node (" null_arg_expr" )), construction_warning );
87
+ remove (node (" null_arg_expr" )), ConstructionWarning );
88
88
89
89
// `std::string_view{null_arg_expr}` and `(std::string_view){null_arg_expr}`
90
90
auto HandleTemporaryCXXTemporaryObjectExprAndCompoundLiteralExpr = makeRule (
@@ -93,28 +93,28 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
93
93
hasAnyArgument (/* `hasArgument` would skip over parens */ anyOf (
94
94
NullLiteral, NullInitList, EmptyInitList)),
95
95
has (expr ().bind (" null_arg_expr" )))),
96
- remove (node (" null_arg_expr" )), construction_warning );
96
+ remove (node (" null_arg_expr" )), ConstructionWarning );
97
97
98
98
// `(std::string_view) null_arg_expr`
99
- auto HandleTemporaryCStyleCastExpr = makeRule (
100
- cStyleCastExpr (
101
- hasSourceExpression ( BasicStringViewConstructingFromNullExpr)),
102
- changeTo (node (" null_arg_expr" ), cat (" {}" )), construction_warning );
99
+ auto HandleTemporaryCStyleCastExpr =
100
+ makeRule ( cStyleCastExpr ( hasSourceExpression (
101
+ BasicStringViewConstructingFromNullExpr)),
102
+ changeTo (node (" null_arg_expr" ), cat (" {}" )), ConstructionWarning );
103
103
104
104
// `static_cast<std::string_view>(null_arg_expr)`
105
- auto HandleTemporaryCXXStaticCastExpr = makeRule (
106
- cxxStaticCastExpr (
107
- hasSourceExpression ( BasicStringViewConstructingFromNullExpr)),
108
- changeTo (node (" null_arg_expr" ), cat (" \"\" " )), static_cast_warning );
105
+ auto HandleTemporaryCXXStaticCastExpr =
106
+ makeRule ( cxxStaticCastExpr ( hasSourceExpression (
107
+ BasicStringViewConstructingFromNullExpr)),
108
+ changeTo (node (" null_arg_expr" ), cat (" \"\" " )), StaticCastWarning );
109
109
110
110
// `std::string_view sv = null_arg_expr;`
111
- auto HandleStackCopyInitialization = makeRule (
112
- varDecl (HasBasicStringViewType,
113
- hasInitializer (ignoringImpCasts (
114
- cxxConstructExpr ( BasicStringViewConstructingFromNullExpr,
115
- unless (isListInitialization ())))),
116
- unless (isDirectInitialization ())),
117
- changeTo (node (" null_arg_expr" ), cat (" {}" )), construction_warning );
111
+ auto HandleStackCopyInitialization =
112
+ makeRule ( varDecl (HasBasicStringViewType,
113
+ hasInitializer (ignoringImpCasts ( cxxConstructExpr (
114
+ BasicStringViewConstructingFromNullExpr,
115
+ unless (isListInitialization ())))),
116
+ unless (isDirectInitialization ())),
117
+ changeTo (node (" null_arg_expr" ), cat (" {}" )), ConstructionWarning );
118
118
119
119
// `std::string_view sv = {null_arg_expr};`
120
120
auto HandleStackCopyListInitialization =
@@ -123,7 +123,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
123
123
BasicStringViewConstructingFromNullExpr,
124
124
isListInitialization ())),
125
125
unless (isDirectInitialization ())),
126
- remove (node (" null_arg_expr" )), construction_warning );
126
+ remove (node (" null_arg_expr" )), ConstructionWarning );
127
127
128
128
// `std::string_view sv(null_arg_expr);`
129
129
auto HandleStackDirectInitialization =
@@ -134,7 +134,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
134
134
isDirectInitialization ())
135
135
.bind (" var_decl" ),
136
136
changeTo (node (" construct_expr" ), cat (name (" var_decl" ))),
137
- construction_warning );
137
+ ConstructionWarning );
138
138
139
139
// `std::string_view sv{null_arg_expr};`
140
140
auto HandleStackDirectListInitialization =
@@ -143,15 +143,15 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
143
143
BasicStringViewConstructingFromNullExpr,
144
144
isListInitialization ())),
145
145
isDirectInitialization ()),
146
- remove (node (" null_arg_expr" )), construction_warning );
146
+ remove (node (" null_arg_expr" )), ConstructionWarning );
147
147
148
148
// `struct S { std::string_view sv = null_arg_expr; };`
149
149
auto HandleFieldInClassCopyInitialization = makeRule (
150
150
fieldDecl (HasBasicStringViewType,
151
151
hasInClassInitializer (ignoringImpCasts (
152
152
cxxConstructExpr (BasicStringViewConstructingFromNullExpr,
153
153
unless (isListInitialization ()))))),
154
- changeTo (node (" null_arg_expr" ), cat (" {}" )), construction_warning );
154
+ changeTo (node (" null_arg_expr" ), cat (" {}" )), ConstructionWarning );
155
155
156
156
// `struct S { std::string_view sv = {null_arg_expr}; };` and
157
157
// `struct S { std::string_view sv{null_arg_expr}; };`
@@ -160,76 +160,75 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
160
160
hasInClassInitializer (ignoringImpCasts (
161
161
cxxConstructExpr (BasicStringViewConstructingFromNullExpr,
162
162
isListInitialization ())))),
163
- remove (node (" null_arg_expr" )), construction_warning );
163
+ remove (node (" null_arg_expr" )), ConstructionWarning );
164
164
165
165
// `class C { std::string_view sv; C() : sv(null_arg_expr) {} };`
166
166
auto HandleConstructorDirectInitialization =
167
167
makeRule (cxxCtorInitializer (forField (fieldDecl (HasBasicStringViewType)),
168
168
withInitializer (cxxConstructExpr (
169
169
BasicStringViewConstructingFromNullExpr,
170
170
unless (isListInitialization ())))),
171
- remove (node (" null_arg_expr" )), construction_warning );
171
+ remove (node (" null_arg_expr" )), ConstructionWarning );
172
172
173
173
// `class C { std::string_view sv; C() : sv{null_arg_expr} {} };`
174
174
auto HandleConstructorDirectListInitialization =
175
175
makeRule (cxxCtorInitializer (forField (fieldDecl (HasBasicStringViewType)),
176
176
withInitializer (cxxConstructExpr (
177
177
BasicStringViewConstructingFromNullExpr,
178
178
isListInitialization ()))),
179
- remove (node (" null_arg_expr" )), construction_warning );
179
+ remove (node (" null_arg_expr" )), ConstructionWarning );
180
180
181
181
// `void f(std::string_view sv = null_arg_expr);`
182
- auto HandleDefaultArgumentCopyInitialization = makeRule (
183
- parmVarDecl (HasBasicStringViewType,
184
- hasInitializer (ignoringImpCasts (
185
- cxxConstructExpr ( BasicStringViewConstructingFromNullExpr,
186
- unless (isListInitialization ()))))),
187
- changeTo (node (" null_arg_expr" ), cat (" {}" )), construction_warning );
182
+ auto HandleDefaultArgumentCopyInitialization =
183
+ makeRule ( parmVarDecl (HasBasicStringViewType,
184
+ hasInitializer (ignoringImpCasts ( cxxConstructExpr (
185
+ BasicStringViewConstructingFromNullExpr,
186
+ unless (isListInitialization ()))))),
187
+ changeTo (node (" null_arg_expr" ), cat (" {}" )), ConstructionWarning );
188
188
189
189
// `void f(std::string_view sv = {null_arg_expr});`
190
190
auto HandleDefaultArgumentCopyListInitialization =
191
191
makeRule (parmVarDecl (HasBasicStringViewType,
192
192
hasInitializer (cxxConstructExpr (
193
193
BasicStringViewConstructingFromNullExpr,
194
194
isListInitialization ()))),
195
- remove (node (" null_arg_expr" )), construction_warning );
195
+ remove (node (" null_arg_expr" )), ConstructionWarning );
196
196
197
197
// `new std::string_view(null_arg_expr)`
198
198
auto HandleHeapDirectInitialization = makeRule (
199
199
cxxNewExpr (has (cxxConstructExpr (BasicStringViewConstructingFromNullExpr,
200
200
unless (isListInitialization ()))),
201
201
unless (isArray ()), unless (hasAnyPlacementArg (anything ()))),
202
- remove (node (" null_arg_expr" )), construction_warning );
202
+ remove (node (" null_arg_expr" )), ConstructionWarning );
203
203
204
204
// `new std::string_view{null_arg_expr}`
205
205
auto HandleHeapDirectListInitialization = makeRule (
206
206
cxxNewExpr (has (cxxConstructExpr (BasicStringViewConstructingFromNullExpr,
207
207
isListInitialization ())),
208
208
unless (isArray ()), unless (hasAnyPlacementArg (anything ()))),
209
- remove (node (" null_arg_expr" )), construction_warning );
209
+ remove (node (" null_arg_expr" )), ConstructionWarning );
210
210
211
211
// `function(null_arg_expr)`
212
212
auto HandleFunctionArgumentInitialization =
213
213
makeRule (callExpr (hasAnyArgument (ignoringImpCasts (
214
214
BasicStringViewConstructingFromNullExpr)),
215
215
unless (cxxOperatorCallExpr ())),
216
216
changeTo (node (" construct_expr" ), cat (" \"\" " )),
217
- argument_construction_warning );
217
+ ArgumentConstructionWarning );
218
218
219
219
// `sv = null_arg_expr`
220
220
auto HandleAssignment = makeRule (
221
221
cxxOperatorCallExpr (hasOverloadedOperatorName (" =" ),
222
222
hasRHS (materializeTemporaryExpr (
223
223
has (BasicStringViewConstructingFromNullExpr)))),
224
- changeTo (node (" construct_expr" ), cat (" {}" )), assignment_warning );
224
+ changeTo (node (" construct_expr" ), cat (" {}" )), AssignmentWarning );
225
225
226
226
// `sv < null_arg_expr`
227
227
auto HandleRelativeComparison = makeRule (
228
228
cxxOperatorCallExpr (hasAnyOverloadedOperatorName (" <" , " <=" , " >" , " >=" ),
229
229
hasEitherOperand (ignoringImpCasts (
230
230
BasicStringViewConstructingFromNullExpr))),
231
- changeTo (node (" construct_expr" ), cat (" \"\" " )),
232
- relative_comparison_warning);
231
+ changeTo (node (" construct_expr" ), cat (" \"\" " )), RelativeComparisonWarning);
233
232
234
233
// `sv == null_arg_expr`
235
234
auto HandleEmptyEqualityComparison = makeRule (
@@ -240,7 +239,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
240
239
expr ().bind (" instance" ))))
241
240
.bind (" root" ),
242
241
changeTo (node (" root" ), cat (access (" instance" , cat (" empty" )), " ()" )),
243
- equality_comparison_warning );
242
+ EqualityComparisonWarning );
244
243
245
244
// `sv != null_arg_expr`
246
245
auto HandleNonEmptyEqualityComparison = makeRule (
@@ -251,13 +250,13 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
251
250
expr ().bind (" instance" ))))
252
251
.bind (" root" ),
253
252
changeTo (node (" root" ), cat (" !" , access (" instance" , cat (" empty" )), " ()" )),
254
- equality_comparison_warning );
253
+ EqualityComparisonWarning );
255
254
256
255
// `return null_arg_expr;`
257
256
auto HandleReturnStatement = makeRule (
258
257
returnStmt (hasReturnValue (
259
258
ignoringImpCasts (BasicStringViewConstructingFromNullExpr))),
260
- changeTo (node (" construct_expr" ), cat (" {}" )), construction_warning );
259
+ changeTo (node (" construct_expr" ), cat (" {}" )), ConstructionWarning );
261
260
262
261
// `T(null_arg_expr)`
263
262
auto HandleConstructorInvocation =
@@ -267,7 +266,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
267
266
BasicStringViewConstructingFromNullExpr)),
268
267
unless (HasBasicStringViewType)),
269
268
changeTo (node (" construct_expr" ), cat (" \"\" " )),
270
- argument_construction_warning );
269
+ ArgumentConstructionWarning );
271
270
272
271
return applyFirst (
273
272
{HandleTemporaryCXXFunctionalCastExpr,
@@ -297,7 +296,7 @@ RewriteRuleWith<std::string> StringviewNullptrCheckImpl() {
297
296
298
297
StringviewNullptrCheck::StringviewNullptrCheck (StringRef Name,
299
298
ClangTidyContext *Context)
300
- : utils::TransformerClangTidyCheck(StringviewNullptrCheckImpl (), Name,
299
+ : utils::TransformerClangTidyCheck(stringviewNullptrCheckImpl (), Name,
301
300
Context) {}
302
301
303
302
} // namespace clang::tidy::bugprone
0 commit comments