[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
Thu Aug 10 13:12:42 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG894140b4fdde: [clang-tidy] Ignore delegate constructors in cppcoreguidelines-pro-type-member… (authored by PiotrZSL).
Changed prior to commit:
https://reviews.llvm.org/D157367?vs=548085&id=549148#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157367/new/
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:`cppcoreguidelines-pro-type-vararg
<clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check to ignore
false-positives in unevaluated context (e.g., ``decltype``, ``sizeof``, ...).
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.549148.patch
Type: text/x-patch
Size: 3406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230810/f739dbdd/attachment.bin>
More information about the cfe-commits
mailing list