[clang-tools-extra] r290972 - [clang-tidy] Ignore default arguments in modernize-default-member-init

Malcolm Parsons via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 09:33:56 PST 2017


Author: malcolm.parsons
Date: Wed Jan  4 11:33:55 2017
New Revision: 290972

URL: http://llvm.org/viewvc/llvm-project?rev=290972&view=rev
Log:
[clang-tidy] Ignore default arguments in modernize-default-member-init

Summary:
Default member initializers cannot refer to constructor parameters, but modernize-default-member-init was trying to when the default constructor had default arguments.

Change the check to ignore default arguments to the default constructor.

Fixes PR31524.

Reviewers: alexfh, aaron.ballman

Subscribers: cfe-commits, JDevlieghere, Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D28287

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=290972&r1=290971&r2=290972&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp Wed Jan  4 11:33:55 2017
@@ -158,7 +158,7 @@ void UseDefaultMemberInitCheck::register
             unaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-")),
                           hasUnaryOperand(floatLiteral())),
             cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
-            declRefExpr());
+            declRefExpr(to(enumConstantDecl())));
 
   Finder->addMatcher(
       cxxConstructorDecl(

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=290972&r1=290971&r2=290972&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp Wed Jan  4 11:33:55 2017
@@ -221,6 +221,12 @@ struct NegativeNotDefaultInt
   int i;
 };
 
+struct NegativeDefaultArg
+{
+  NegativeDefaultArg(int i = 4) : i(i) {}
+  int i;
+};
+
 struct ExistingChar {
   ExistingChar(short) : e1(), e2(), e3(), e4() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]




More information about the cfe-commits mailing list