AMS21 updated this revision to Diff 530892. AMS21 marked an inline comment as done. AMS21 added a comment.
Still issue a warning just no fixit Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D152802/new/ https://reviews.llvm.org/D152802 Files: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp @@ -482,3 +482,19 @@ // CHECK-FIXES: {{^ }}EmptyBracedIntDefault() {} // CHECK-FIXES-NEXT: {{^ }}int m_i{}; }; + +namespace PR63285 { + +class ArrayValueInit { + double m_array[1]; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] + ArrayValueInit() : m_array() {} +}; + +class ArrayBraceInit { + double m_array[1]; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] + ArrayBraceInit() : m_array{} {} +}; + +} // namespace PR63285 Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp @@ -190,3 +190,19 @@ NegativeTemplate<int> nti; NegativeTemplate<double> ntd; + +namespace PR63285 { + +class ArrayValueInit { + double m_array[1]; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] + ArrayValueInit() : m_array() {} +}; + +class ArrayBraceInit { + double m_array[1]; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] + ArrayBraceInit() : m_array{} {} +}; + +} // namespace PR63285 Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -325,6 +325,10 @@ constructors toward hand written constructors so that they are skipped if more than one exists. +- Fixed crash in :doc:`modernize-use-default-member-init + <clang-tidy/checks/modernize/use-default-member-init>` with array members which + are value initialized. + - Fixed false positive in :doc:`modernize-use-equals-default <clang-tidy/checks/modernize/use-equals-default>` check for special member functions containing macros or preprocessor directives, and out-of-line special Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp @@ -267,18 +267,26 @@ CharSourceRange InitRange = CharSourceRange::getCharRange(LParenEnd, Init->getRParenLoc()); - bool ValueInit = isa<ImplicitValueInitExpr>(Init->getInit()); - bool CanAssign = UseAssignment && (!ValueInit || !Init->getInit()->getType()->isEnumeralType()); + const Expr *InitExpression = Init->getInit(); + const QualType InitType = InitExpression->getType(); + + const bool ValueInit = isa<ImplicitValueInitExpr>(InitExpression); + const bool CanAssign = + UseAssignment && (!ValueInit || !InitType->isEnumeralType()); auto Diag = diag(Field->getLocation(), "use default member initializer for %0") - << Field - << FixItHint::CreateInsertion(FieldEnd, CanAssign ? " = " : "{") - << FixItHint::CreateInsertionFromRange(FieldEnd, InitRange); + << Field; + + // Don't create FixItHint for arrays + if (isa<ArrayType>(InitType)) + return; + + Diag << FixItHint::CreateInsertion(FieldEnd, CanAssign ? " = " : "{") + << FixItHint::CreateInsertionFromRange(FieldEnd, InitRange); if (CanAssign && ValueInit) - Diag << FixItHint::CreateInsertion( - FieldEnd, getValueOfValueInit(Init->getInit()->getType())); + Diag << FixItHint::CreateInsertion(FieldEnd, getValueOfValueInit(InitType)); if (!CanAssign) Diag << FixItHint::CreateInsertion(FieldEnd, "}"); @@ -294,8 +302,7 @@ return; diag(Init->getSourceLocation(), "member initializer for %0 is redundant") - << Field - << FixItHint::CreateRemoval(Init->getSourceRange()); + << Field << FixItHint::CreateRemoval(Init->getSourceRange()); } } // namespace clang::tidy::modernize
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits