diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -281,8 +281,14 @@ void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) { auto IsUserProvidedNonDelegatingConstructor = - allOf(isUserProvided(), - unless(anyOf(isInstantiated(), isDelegatingConstructor()))); + allOf(isUserProvided(), unless(isInstantiated()), + unless(isDelegatingConstructor()), + ofClass(cxxRecordDecl().bind("parent")), + unless(hasAnyConstructorInitializer(cxxCtorInitializer( + isWritten(), unless(isMemberInitializer()), + hasTypeLoc(loc( + qualType(hasDeclaration(equalsBoundNode("parent"))))))))); + auto IsNonTrivialDefaultConstructor = allOf( isDefaultConstructor(), unless(isUserProvided()), hasParent(cxxRecordDecl(unless(isTriviallyDefaultConstructible())))); 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 @@ -176,6 +176,10 @@ ` check to ignore delegate constructors. +- Improved :doc:`cppcoreguidelines-pro-type-member-init + ` check to ignore + dependent delegate constructors. + - Improved :doc:`llvm-namespace-comment ` check to provide fixes for ``inline`` namespaces in the same format as :program:`clang-format`. diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp @@ -372,8 +372,7 @@ class PositiveSelfInitialization : NegativeAggregateType { PositiveSelfInitialization() : PositiveSelfInitialization() {} - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType - // CHECK-FIXES: PositiveSelfInitialization() : NegativeAggregateType(), PositiveSelfInitialization() {} + // This will be detected by -Wdelegating-ctor-cycles and there is no proper way to fix this }; class PositiveIndirectMember { @@ -579,3 +578,42 @@ int C = 0; }; }; + +// Ignore issues from delegate constructors +namespace PR37250 { + template + struct A { + A() : A(42) {} + explicit A(int value) : value_(value) {} + int value_; + }; + + struct B { + B() : B(42) {} + explicit B(int value) : value_(value) {} + int value_; + }; + + template + struct C { + C() : C(T()) {} + explicit C(T value) : value_(value) {} + T value_; + }; + + struct V { + unsigned size() const; + }; + + struct S { + unsigned size_; + + S(unsigned size) : size_{size} {} + + template + S(const U& u) : S(u.size()) {} + }; + + const V v; + const S s{v}; +}