[PATCH] D157367: [clang-tidy] Ignore delegate constructors in cppcoreguidelines-pro-type-member-init
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 8 00:19:58 PDT 2023
PiotrZSL created this revision.
PiotrZSL added reviewers: carlosgalvezp, njames93, ccotter.
Herald added subscribers: shchenz, kbarton, xazax.hun, nemanjai.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
Ignore dependend delegate constructors.
Fixes: #37250
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157367
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
+++ 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 <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};
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@
<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:`llvm-namespace-comment
<clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for
``inline`` namespaces in the same format as :program:`clang-format`.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ 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()))));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157367.548085.patch
Type: text/x-patch
Size: 3386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230808/973d63a2/attachment.bin>
More information about the cfe-commits
mailing list