malcolm.parsons created this revision. malcolm.parsons added a reviewer: klimek. malcolm.parsons added subscribers: cfe-commits, klimek, alexfh.
Only member initializers that are written should prevent using '= default' on a default constructor. https://reviews.llvm.org/D24444 Files: clang-tidy/modernize/UseDefaultCheck.cpp test/clang-tidy/modernize-use-default.cpp Index: test/clang-tidy/modernize-use-default.cpp =================================================================== --- test/clang-tidy/modernize-use-default.cpp +++ test/clang-tidy/modernize-use-default.cpp @@ -43,6 +43,24 @@ 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() {} Index: clang-tidy/modernize/UseDefaultCheck.cpp =================================================================== --- clang-tidy/modernize/UseDefaultCheck.cpp +++ clang-tidy/modernize/UseDefaultCheck.cpp @@ -238,7 +238,7 @@ isDefinition(), anyOf( // Default constructor. - allOf(unless(hasAnyConstructorInitializer(anything())), + allOf(unless(hasAnyConstructorInitializer(isWritten())), parameterCountIs(0)), // Copy constructor. allOf(isCopyConstructor(), @@ -296,12 +296,12 @@ 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";
Index: test/clang-tidy/modernize-use-default.cpp =================================================================== --- test/clang-tidy/modernize-use-default.cpp +++ test/clang-tidy/modernize-use-default.cpp @@ -43,6 +43,24 @@ 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() {} Index: clang-tidy/modernize/UseDefaultCheck.cpp =================================================================== --- clang-tidy/modernize/UseDefaultCheck.cpp +++ clang-tidy/modernize/UseDefaultCheck.cpp @@ -238,7 +238,7 @@ isDefinition(), anyOf( // Default constructor. - allOf(unless(hasAnyConstructorInitializer(anything())), + allOf(unless(hasAnyConstructorInitializer(isWritten())), parameterCountIs(0)), // Copy constructor. allOf(isCopyConstructor(), @@ -296,12 +296,12 @@ 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";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits