Author: Piotr Zegar Date: 2023-08-07T06:08:39Z New Revision: 7a4b12e39b84d6991be2431e296916353f04b0de
URL: https://github.com/llvm/llvm-project/commit/7a4b12e39b84d6991be2431e296916353f04b0de DIFF: https://github.com/llvm/llvm-project/commit/7a4b12e39b84d6991be2431e296916353f04b0de.diff LOG: [clang-tidy] Exclude delegate constructors in cppcoreguidelines-prefer-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 Added: Modified: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp index 80b8c9211792ad..152db151f78ec7 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp @@ -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( diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 998242f9a5c4c0..2af86407069a68 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -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`. diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp index e1929c2a3f0550..9d7aad52c8fa80 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp @@ -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; +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits