diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp @@ -246,8 +246,12 @@ // Check whether we have multiple hand-written constructors and bomb out, as // it is hard to reconcile their sets of member initializers. const auto *ClassDecl = cast(Field->getParent()); - if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) { - return !Ctor->isCopyOrMoveConstructor(); + if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) { + if (const auto *FTD = dyn_cast(D)) + D = FTD->getTemplatedDecl(); + if (const auto *Ctor = dyn_cast(D)) + return !Ctor->isCopyOrMoveConstructor(); + return false; }) > 1) return; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -169,6 +169,11 @@ ` check. Global options of the same name should be used instead. +- In :doc:`modernize-use-default-member-init + ` count template + constructors toward hand written constructors so that they are skipped if more + than one exists. + - Fixed reading `HungarianNotation.CString.*` options in :doc:`readability-identifier-naming ` check. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp @@ -60,6 +60,12 @@ int i; }; +struct TwoConstructorsTpl { + TwoConstructorsTpl() : i{7} {} + template TwoConstructorsTpl(T, int) : i(8) {} + int i; +}; + struct PositiveNotDefaultOOLInt { PositiveNotDefaultOOLInt(int); int i;