[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
Wed Apr 1 01:36:58 PDT 2020
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
Fixes incorrect warning emitted by "modernize-use-default-member-init" (new to 10.0.0) <https://bugs.llvm.org/show_bug.cgi?id=45363>.
Repository:
rG LLVM Github Monorepo
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,9 @@
// 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;
+};
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.254109.patch
Type: text/x-patch
Size: 2132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200401/6c5b152a/attachment-0001.bin>
More information about the cfe-commits
mailing list