Skip to content

Commit

Permalink
[clang-tidy] Ignore delegate constructors in cppcoreguidelines-pro-ty…
Browse files Browse the repository at this point in the history
…pe-member-init

Ignore dependend delegate constructors.

Fixes: #37250

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D157367
  • Loading branch information
PiotrZSL committed Aug 10, 2023
1 parent 7f29f14 commit 894140b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,14 @@ ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name,

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()))));
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ Changes in existing checks
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
ignore delegate constructors.

- Improved :doc:`cppcoreguidelines-pro-type-member-init
<clang-tidy/checks/cppcoreguidelines/pro-type-member-init>` check to ignore
dependent delegate constructors.

- Improved :doc:`cppcoreguidelines-pro-type-vararg
<clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check to ignore
false-positives in unevaluated context (e.g., ``decltype``, ``sizeof``, ...).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ template <typename T>
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 {
Expand Down Expand Up @@ -579,3 +578,42 @@ struct S3 {
int C = 0;
};
};

// Ignore issues from delegate constructors
namespace PR37250 {
template <typename T>
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 <typename T>
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<typename U>
S(const U& u) : S(u.size()) {}
};

const V v;
const S s{v};
}

0 comments on commit 894140b

Please sign in to comment.