[PATCH] D77199: [clang-tidy] Address false positive in modernize-use-default-member-init
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 11:55:21 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2c7ea1c4c5f7: [clang-tidy] Address false positive in modernize-use-default-member-init (authored by njames93).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77199/new/
https://reviews.llvm.org/D77199
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
@@ -432,3 +432,17 @@
// CHECK-MESSAGES: :[[@LINE-2]]:10: warning: use default member initializer for 'k' [modernize-use-default-member-init]
// CHECK-FIXES: int i{5}, k{8};
};
+
+struct PR45363 {
+ // Ensure no warning is emitted here
+ PR45363(int i = 0) : m_i{i} {}
+ int m_i;
+};
+
+struct EmptyBracedIntDefault {
+ EmptyBracedIntDefault() : m_i{} {}
+ int m_i;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'm_i' [modernize-use-default-member-init]
+ // CHECK-FIXES: {{^ }}EmptyBracedIntDefault() {}
+ // CHECK-FIXES-NEXT: {{^ }}int m_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
@@ -17,6 +17,12 @@
namespace tidy {
namespace modernize {
+namespace {
+AST_MATCHER_P(InitListExpr, initCountIs, unsigned, N) {
+ return Node.getNumInits() == N;
+}
+} // namespace
+
static StringRef getValueOfValueInit(const QualType InitType) {
switch (InitType->getScalarTypeKind()) {
case Type::STK_CPointer:
@@ -190,7 +196,7 @@
}
void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
- auto Init =
+ auto InitBase =
anyOf(stringLiteral(), characterLiteral(), integerLiteral(),
unaryOperator(hasAnyOperatorName("+", "-"),
hasUnaryOperand(integerLiteral())),
@@ -198,7 +204,13 @@
unaryOperator(hasAnyOperatorName("+", "-"),
hasUnaryOperand(floatLiteral())),
cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
- initListExpr(), declRefExpr(to(enumConstantDecl())));
+ declRefExpr(to(enumConstantDecl())));
+
+ auto Init =
+ anyOf(initListExpr(anyOf(
+ allOf(initCountIs(1), hasInit(0, ignoringImplicit(InitBase))),
+ initCountIs(0))),
+ InitBase);
Finder->addMatcher(
cxxConstructorDecl(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77199.254876.patch
Type: text/x-patch
Size: 2446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200403/44986a79/attachment.bin>
More information about the cfe-commits
mailing list