alexander-shaposhnikov updated this revision to Diff 469093. Repository: rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D136224/new/ https://reviews.llvm.org/D136224 Files: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx17.cpp clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx20.cpp clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp @@ -90,14 +90,16 @@ // Private constructor/destructor. class Priv { - Priv() {} - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' - // CHECK-FIXES: Priv() = default; + Priv(); ~Priv() {}; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' // CHECK-FIXES: ~Priv() = default; }; +Priv::Priv() {} +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use '= default' +// CHECK-FIXES: Priv::Priv() = default; + // struct. struct ST { ST() {} Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx20.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx20.cpp @@ -0,0 +1,19 @@ +// RUN: %check_clang_tidy -std=c++20 %s modernize-use-equals-default %t -- -- -fno-delayed-template-parsing -fexceptions + +// Private constructor/destructor. +class Priv { + Priv() {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' + // CHECK-FIXES: Priv() = default; + ~Priv() {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' + // CHECK-FIXES: ~Priv() = default; +}; + +class PrivOutOfLine { + PrivOutOfLine(); +}; + +PrivOutOfLine::PrivOutOfLine() {} +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use '= default' +// CHECK-FIXES: PrivOutOfLine::PrivOutOfLine() = default; Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx17.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx17.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy -std=c++17 %s modernize-use-equals-default %t -- -- -fno-delayed-template-parsing -fexceptions + +// Private constructor/destructor. +class Priv { + Priv() {} + ~Priv() {} + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' + // CHECK-FIXES: ~Priv() = default; +}; + +class PrivOutOfLine { + PrivOutOfLine(); +}; + +PrivOutOfLine::PrivOutOfLine() {} +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use '= default' +// CHECK-FIXES: PrivOutOfLine::PrivOutOfLine() = default; Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -158,7 +158,8 @@ The check now skips unions/union-like classes since in this case a default constructor with empty body is not equivalent to the explicitly defaulted one, variadic constructors since they cannot be explicitly defaulted. The check also skips copy assignment operators - with nonstandard return types. The check is restricted to c++11-or-later. + with nonstandard return types, private/protected default constructors for C++17 or earlier. + The check is restricted to C++11 or later. - Change the default behavior of :doc:`readability-avoid-const-params-in-decls <clang-tidy/checks/readability/avoid-const-params-in-decls>` to not Index: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp @@ -217,6 +217,10 @@ Options.store(Opts, "IgnoreMacros", IgnoreMacros); } +namespace { +AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); } +} // namespace + void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) { // Skip unions/union-like classes since their constructors behave differently // when defaulted vs. empty. @@ -224,6 +228,12 @@ anyOf(isUnion(), has(fieldDecl(isImplicit(), hasType(cxxRecordDecl(isUnion())))))); + const LangOptions &LangOpts = getLangOpts(); + auto IsPublicOrOutOfLineUntilCPP20 = + LangOpts.CPlusPlus20 + ? cxxConstructorDecl() + : cxxConstructorDecl(anyOf(isOutOfLine(), isPublic())); + // Destructor. Finder->addMatcher( cxxDestructorDecl(unless(hasParent(IsUnionLikeClass)), isDefinition()) @@ -235,7 +245,8 @@ anyOf( // Default constructor. allOf(unless(hasAnyConstructorInitializer(isWritten())), - unless(isVariadic()), parameterCountIs(0)), + unless(isVariadic()), parameterCountIs(0), + IsPublicOrOutOfLineUntilCPP20), // Copy constructor. allOf(isCopyConstructor(), // Discard constructors that can be used as a copy
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits