[clang-tools-extra] r283869 - [clang-tidy] modernize-use-default default constructor bugfix
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 11 03:47:07 PDT 2016
Author: malcolm.parsons
Date: Tue Oct 11 05:47:06 2016
New Revision: 283869
URL: http://llvm.org/viewvc/llvm-project?rev=283869&view=rev
Log:
[clang-tidy] modernize-use-default default constructor bugfix
Summary:
Only member initializers that are written should prevent
using '= default' on a default constructor.
Reviewers: klimek, sbenza, aaron.ballman, alexfh
Subscribers: Eugene.Zelenko, alexfh, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D24444
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp?rev=283869&r1=283868&r2=283869&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp Tue Oct 11 05:47:06 2016
@@ -238,7 +238,7 @@ void UseDefaultCheck::registerMatchers(M
isDefinition(),
anyOf(
// Default constructor.
- allOf(unless(hasAnyConstructorInitializer(anything())),
+ allOf(unless(hasAnyConstructorInitializer(isWritten())),
parameterCountIs(0)),
// Copy constructor.
allOf(isCopyConstructor(),
@@ -296,12 +296,12 @@ void UseDefaultCheck::check(const MatchF
if (!isCopyConstructorAndCanBeDefaulted(Result.Context, Ctor))
return;
SpecialFunctionName = "copy constructor";
- }
- // If there are constructor initializers, they must be removed.
- if (Ctor->getNumCtorInitializers() != 0) {
- StartLoc = getColonLoc(Result.Context, Ctor);
- if (!StartLoc.isValid())
- return;
+ // If there are constructor initializers, they must be removed.
+ if (Ctor->getNumCtorInitializers() != 0) {
+ StartLoc = getColonLoc(Result.Context, Ctor);
+ if (!StartLoc.isValid())
+ return;
+ }
}
} else if (isa<CXXDestructorDecl>(SpecialFunctionDecl)) {
SpecialFunctionName = "destructor";
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp?rev=283869&r1=283868&r2=283869&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp Tue Oct 11 05:47:06 2016
@@ -43,6 +43,24 @@ public:
int Field;
};
+// Default member initializer
+class DMI {
+public:
+ DMI() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: DMI() = default;
+ int Field = 5;
+};
+
+// Class member
+class CM {
+public:
+ CM() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+ // CHECK-FIXES: CM() = default;
+ OL o;
+};
+
// Private constructor/destructor.
class Priv {
Priv() {}
More information about the cfe-commits
mailing list