[PATCH] D114995: clang-tidy: improve the 'modernize-use-default-member-init'
Oleg Smolsky via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 2 17:04:32 PST 2021
oleg.smolsky updated this revision to Diff 391503.
oleg.smolsky added a comment.
Ran `clang-format` on the test cases.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114995/new/
https://reviews.llvm.org/D114995
Files:
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp
@@ -45,6 +45,35 @@
// CHECK-FIXES: int j{1};
};
+struct PositiveNotDefaultInt {
+ PositiveNotDefaultInt(int) : i(7) {}
+ // CHECK-FIXES: PositiveNotDefaultInt(int) {}
+ int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
+ // CHECK-FIXES: int i{7};
+};
+
+struct PositiveNotDefaultOOLInt {
+ PositiveNotDefaultOOLInt(int);
+ int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
+ // CHECK-FIXES: int i{7};
+};
+
+PositiveNotDefaultOOLInt::PositiveNotDefaultOOLInt(int) : i(7) {}
+// CHECK-FIXES: PositiveNotDefaultOOLInt::PositiveNotDefaultOOLInt(int) {}
+
+struct PositiveNotDefaultOOLInt2 {
+ PositiveNotDefaultOOLInt2(int, int);
+ int i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
+ // CHECK-FIXES: int i{7};
+ int j;
+};
+
+PositiveNotDefaultOOLInt2::PositiveNotDefaultOOLInt2(int, int arg) : i(7), j(arg) {}
+// CHECK-FIXES: PositiveNotDefaultOOLInt2::PositiveNotDefaultOOLInt2(int, int arg) : j(arg) {}
+
struct PositiveUnaryMinusInt {
PositiveUnaryMinusInt() : j(-1) {}
// CHECK-FIXES: PositiveUnaryMinusInt() {}
@@ -234,12 +263,6 @@
int i : 5;
};
-struct NegativeNotDefaultInt
-{
- NegativeNotDefaultInt(int) : i(7) {}
- int i;
-};
-
struct NegativeDefaultArg
{
NegativeDefaultArg(int i = 4) : i(i) {}
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -212,17 +212,14 @@
InitBase);
Finder->addMatcher(
- cxxConstructorDecl(
- isDefaultConstructor(),
- forEachConstructorInitializer(
- cxxCtorInitializer(
- forField(unless(anyOf(getLangOpts().CPlusPlus20
- ? unless(anything())
- : isBitField(),
- hasInClassInitializer(anything()),
- hasParent(recordDecl(isUnion()))))),
- withInitializer(Init))
- .bind("default"))),
+ cxxConstructorDecl(forEachConstructorInitializer(
+ cxxCtorInitializer(
+ forField(unless(anyOf(
+ getLangOpts().CPlusPlus20 ? unless(anything()) : isBitField(),
+ hasInClassInitializer(anything()),
+ hasParent(recordDecl(isUnion()))))),
+ withInitializer(Init))
+ .bind("default"))),
this);
Finder->addMatcher(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114995.391503.patch
Type: text/x-patch
Size: 3060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211203/9a888361/attachment-0001.bin>
More information about the cfe-commits
mailing list