File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,8 @@ void UseDefaultMemberInitCheck::storeOptions(
194
194
}
195
195
196
196
void UseDefaultMemberInitCheck::registerMatchers (MatchFinder *Finder) {
197
+ auto ConstExpRef = varDecl (anyOf (isConstexpr (), isStaticStorageClass ()));
198
+
197
199
auto InitBase =
198
200
anyOf (stringLiteral (), characterLiteral (), integerLiteral (),
199
201
unaryOperator (hasAnyOperatorName (" +" , " -" ),
@@ -202,7 +204,7 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
202
204
unaryOperator (hasAnyOperatorName (" +" , " -" ),
203
205
hasUnaryOperand (floatLiteral ())),
204
206
cxxBoolLiteral (), cxxNullPtrLiteralExpr (), implicitValueInitExpr (),
205
- declRefExpr (to (enumConstantDecl ())));
207
+ declRefExpr (to (anyOf ( enumConstantDecl (), ConstExpRef ))));
206
208
207
209
auto Init =
208
210
anyOf (initListExpr (anyOf (allOf (initCountIs (1 ), hasInit (0 , InitBase)),
Original file line number Diff line number Diff line change @@ -146,6 +146,10 @@ Changes in existing checks
146
146
<clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives
147
147
for function or variable in header file which contains macro expansion.
148
148
149
+ - Improved :doc: `modernize-use-default-member-init
150
+ <clang-tidy/checks/modernize/use-default-member-init>` check by matching
151
+ ``constexpr `` and ``static `` values on member initialization.
152
+
149
153
- Improved :doc: `performance/unnecessary-value-param
150
154
<clang-tidy/checks/performance/unnecessary-value-param>` check performance by
151
155
tolerating fix-it breaking compilation when functions is used as pointers
Original file line number Diff line number Diff line change @@ -518,3 +518,22 @@ class ArrayBraceInitMultipleValues {
518
518
};
519
519
520
520
} // namespace PR63285
521
+
522
+ namespace PR122480 {
523
+
524
+ static int STATIC_VAL = 23 ;
525
+ constexpr const char * CONSTEXPR_REF = " Const" ;
526
+
527
+ class StaticConstExprInit {
528
+
529
+ StaticConstExprInit () : a{CONSTEXPR_REF}, b{STATIC_VAL}{}
530
+ // CHECK-FIXES: StaticConstExprInit() {}
531
+ const char * a;
532
+ // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use default member initializer for 'a' [modernize-use-default-member-init]
533
+ // CHECK-FIXES: const char* a{CONSTEXPR_REF};
534
+ int b;
535
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'b' [modernize-use-default-member-init]
536
+ // CHECK-FIXES: int b{STATIC_VAL};
537
+ };
538
+
539
+ } // namespace PR122480
You can’t perform that action at this time.
0 commit comments