[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 13:50:19 PST 2021
oleg.smolsky created this revision.
Herald added a subscriber: carlosgalvezp.
oleg.smolsky requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
- we want to deal with non-default constructors that just happen to contain constant initializers
There was already a negative test case, it is now a positive one. We find and refactor this case:
struct PositiveNotDefaultInt {
PositiveNotDefaultInt(int) : i(7) {}
int i;
};
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114995
Files:
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
test/clang-tidy/checkers/modernize-use-default-member-init.cpp
Index: test/clang-tidy/checkers/modernize-use-default-member-init.cpp
===================================================================
--- test/clang-tidy/checkers/modernize-use-default-member-init.cpp
+++ test/clang-tidy/checkers/modernize-use-default-member-init.cpp
@@ -45,6 +45,15 @@
// 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 PositiveUnaryMinusInt {
PositiveUnaryMinusInt() : j(-1) {}
// CHECK-FIXES: PositiveUnaryMinusInt() {}
@@ -234,12 +243,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
@@ -213,7 +213,6 @@
Finder->addMatcher(
cxxConstructorDecl(
- isDefaultConstructor(),
forEachConstructorInitializer(
cxxCtorInitializer(
forField(unless(anyOf(getLangOpts().CPlusPlus20
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114995.391448.patch
Type: text/x-patch
Size: 1441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211202/28f5943e/attachment.bin>
More information about the cfe-commits
mailing list