Skip to content

Commit 894140b

Browse files
committed
[clang-tidy] Ignore delegate constructors in cppcoreguidelines-pro-type-member-init
Ignore dependend delegate constructors. Fixes: #37250 Reviewed By: ccotter Differential Revision: https://reviews.llvm.org/D157367
1 parent 7f29f14 commit 894140b

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,14 @@ ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name,
281281

282282
void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) {
283283
auto IsUserProvidedNonDelegatingConstructor =
284-
allOf(isUserProvided(),
285-
unless(anyOf(isInstantiated(), isDelegatingConstructor())));
284+
allOf(isUserProvided(), unless(isInstantiated()),
285+
unless(isDelegatingConstructor()),
286+
ofClass(cxxRecordDecl().bind("parent")),
287+
unless(hasAnyConstructorInitializer(cxxCtorInitializer(
288+
isWritten(), unless(isMemberInitializer()),
289+
hasTypeLoc(loc(
290+
qualType(hasDeclaration(equalsBoundNode("parent")))))))));
291+
286292
auto IsNonTrivialDefaultConstructor = allOf(
287293
isDefaultConstructor(), unless(isUserProvided()),
288294
hasParent(cxxRecordDecl(unless(isTriviallyDefaultConstructible()))));

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ Changes in existing checks
176176
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
177177
ignore delegate constructors.
178178

179+
- Improved :doc:`cppcoreguidelines-pro-type-member-init
180+
<clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check to ignore
181+
dependent delegate constructors.
182+
179183
- Improved :doc:`cppcoreguidelines-pro-type-vararg
180184
<clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check to ignore
181185
false-positives in unevaluated context (e.g., ``decltype``, ``sizeof``, ...).

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ template <typename T>
372372
class PositiveSelfInitialization : NegativeAggregateType
373373
{
374374
PositiveSelfInitialization() : PositiveSelfInitialization() {}
375-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType
376-
// CHECK-FIXES: PositiveSelfInitialization() : NegativeAggregateType(), PositiveSelfInitialization() {}
375+
// This will be detected by -Wdelegating-ctor-cycles and there is no proper way to fix this
377376
};
378377

379378
class PositiveIndirectMember {
@@ -579,3 +578,42 @@ struct S3 {
579578
int C = 0;
580579
};
581580
};
581+
582+
// Ignore issues from delegate constructors
583+
namespace PR37250 {
584+
template <typename T>
585+
struct A {
586+
A() : A(42) {}
587+
explicit A(int value) : value_(value) {}
588+
int value_;
589+
};
590+
591+
struct B {
592+
B() : B(42) {}
593+
explicit B(int value) : value_(value) {}
594+
int value_;
595+
};
596+
597+
template <typename T>
598+
struct C {
599+
C() : C(T()) {}
600+
explicit C(T value) : value_(value) {}
601+
T value_;
602+
};
603+
604+
struct V {
605+
unsigned size() const;
606+
};
607+
608+
struct S {
609+
unsigned size_;
610+
611+
S(unsigned size) : size_{size} {}
612+
613+
template<typename U>
614+
S(const U& u) : S(u.size()) {}
615+
};
616+
617+
const V v;
618+
const S s{v};
619+
}

0 commit comments

Comments
 (0)