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(
194194}
195195
196196void UseDefaultMemberInitCheck::registerMatchers (MatchFinder *Finder) {
197+ auto ConstExpRef = varDecl (anyOf (isConstexpr (), isStaticStorageClass ()));
198+
197199 auto InitBase =
198200 anyOf (stringLiteral (), characterLiteral (), integerLiteral (),
199201 unaryOperator (hasAnyOperatorName (" +" , " -" ),
@@ -202,7 +204,7 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
202204 unaryOperator (hasAnyOperatorName (" +" , " -" ),
203205 hasUnaryOperand (floatLiteral ())),
204206 cxxBoolLiteral (), cxxNullPtrLiteralExpr (), implicitValueInitExpr (),
205- declRefExpr (to (enumConstantDecl ())));
207+ declRefExpr (to (anyOf ( enumConstantDecl (), ConstExpRef ))));
206208
207209 auto Init =
208210 anyOf (initListExpr (anyOf (allOf (initCountIs (1 ), hasInit (0 , InitBase)),
Original file line number Diff line number Diff line change @@ -128,6 +128,10 @@ Changes in existing checks
128128 <clang-tidy/checks/misc/redundant-expression>` check by providing additional
129129 examples and fixing some macro related false positives.
130130
131+ - Improved :doc: `modernize-use-default-member-init
132+ <clang-tidy/checks/modernize/use-default-member-init>` check by Adding check on
133+ constexpr & static values on member initialization.
134+
131135- Improved :doc: `performance/unnecessary-value-param
132136 <clang-tidy/checks/performance/unnecessary-value-param>` check performance by
133137 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 {
518518};
519519
520520} // namespace PR63285
521+
522+ namespace PR122480 {
523+
524+ static int STATIC_VAL = 23 ;
525+ static constexpr const char * CONSTEXPR_REF = " Static" ;
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