This revision was automatically updated to reflect the committed changes. Closed by commit rL283869: [clang-tidy] modernize-use-default default constructor bugfix (authored by malcolm.parsons).
Changed prior to commit: https://reviews.llvm.org/D24444?vs=70966&id=74232#toc Repository: rL LLVM https://reviews.llvm.org/D24444 Files: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp +++ clang-tools-extra/trunk/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-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp +++ clang-tools-extra/trunk/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: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp +++ clang-tools-extra/trunk/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-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp +++ clang-tools-extra/trunk/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