Skip to content

Commit

Permalink
[clang-tidy] Exclude delegate constructors in cppcoreguidelines-prefe…
Browse files Browse the repository at this point in the history
…r-member-initializer

As proposed by check fix would result in compilation error,
lets exclude delegate constructors from being checked.

Fixes: #52818

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D157242
  • Loading branch information
PiotrZSL committed Aug 7, 2023
1 parent 3dc413e commit 7a4b12e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ void PreferMemberInitializerCheck::storeOptions(
}

void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxConstructorDecl(hasBody(compoundStmt()), unless(isInstantiated()))
.bind("ctor"),
this);
Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
unless(isInstantiated()),
unless(isDelegatingConstructor()))
.bind("ctor"),
this);
}

void PreferMemberInitializerCheck::check(
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 @@ -172,6 +172,10 @@ Changes in existing checks
to ignore ``static`` variables declared within the scope of
``class``/``struct``.

- Improved :doc:`cppcoreguidelines-prefer-member-initializer
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
ignore delegate constructors.

- Improved :doc:`llvm-namespace-comment
<clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for
``inline`` namespaces in the same format as :program:`clang-format`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,10 @@ struct MacroCantFix {
// CHECK-FIXES: ASSIGN_IN_MACRO(n, 0)
}
};

struct PR52818 {
PR52818() : bar(5) {}
PR52818(int) : PR52818() { bar = 3; }

int bar;
};

0 comments on commit 7a4b12e

Please sign in to comment.