diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt --- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt @@ -10,7 +10,6 @@ ContainerSizeEmptyCheck.cpp ConvertMemberFunctionsToStatic.cpp DeleteNullPointerCheck.cpp - DeletedDefaultCheck.cpp ElseAfterReturnCheck.cpp FunctionCognitiveComplexityCheck.cpp FunctionSizeCheck.cpp diff --git a/clang-tools-extra/clang-tidy/readability/DeletedDefaultCheck.h b/clang-tools-extra/clang-tidy/readability/DeletedDefaultCheck.h deleted file mode 100644 --- a/clang-tools-extra/clang-tidy/readability/DeletedDefaultCheck.h +++ /dev/null @@ -1,35 +0,0 @@ -//===--- DeletedDefaultCheck.h - clang-tidy----------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETED_DEFAULT_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETED_DEFAULT_H - -#include "../ClangTidyCheck.h" - -namespace clang { -namespace tidy { -namespace readability { - -/// Checks when a constructor or an assignment operator is marked as '= default' -/// but is actually deleted by the compiler. -/// -/// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/readability-deleted-default.html -class DeletedDefaultCheck : public ClangTidyCheck { -public: - DeletedDefaultCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace readability -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_DELETED_DEFAULT_H diff --git a/clang-tools-extra/clang-tidy/readability/DeletedDefaultCheck.cpp b/clang-tools-extra/clang-tidy/readability/DeletedDefaultCheck.cpp deleted file mode 100644 --- a/clang-tools-extra/clang-tidy/readability/DeletedDefaultCheck.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//===--- DeletedDefaultCheck.cpp - clang-tidy------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "DeletedDefaultCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace readability { - -void DeletedDefaultCheck::registerMatchers(MatchFinder *Finder) { - // We match constructors/assignment operators that are: - // - explicitly marked '= default' - // - actually deleted - // - not in template instantiation. - // We bind the declaration to "method-decl" and also to "constructor" when - // it is a constructor. - - Finder->addMatcher( - cxxMethodDecl(anyOf(cxxConstructorDecl().bind("constructor"), - isCopyAssignmentOperator(), - isMoveAssignmentOperator()), - isDefaulted(), unless(isImplicit()), isDeleted(), - unless(isInstantiated())) - .bind("method-decl"), - this); -} - -void DeletedDefaultCheck::check(const MatchFinder::MatchResult &Result) { - const StringRef Message = "%0 is explicitly defaulted but implicitly " - "deleted, probably because %1; definition can " - "either be removed or explicitly deleted"; - if (const auto *Constructor = - Result.Nodes.getNodeAs("constructor")) { - auto Diag = diag(Constructor->getBeginLoc(), Message); - if (Constructor->isDefaultConstructor()) { - Diag << "default constructor" - << "a non-static data member or a base class is lacking a default " - "constructor"; - } else if (Constructor->isCopyConstructor()) { - Diag << "copy constructor" - << "a non-static data member or a base class is not copyable"; - } else if (Constructor->isMoveConstructor()) { - Diag << "move constructor" - << "a non-static data member or a base class is neither copyable " - "nor movable"; - } - } else if (const auto *Assignment = - Result.Nodes.getNodeAs("method-decl")) { - diag(Assignment->getBeginLoc(), Message) - << (Assignment->isCopyAssignmentOperator() ? "copy assignment operator" - : "move assignment operator") - << "a base class or a non-static data member is not assignable, e.g. " - "because the latter is marked 'const'"; - } -} - -} // namespace readability -} // namespace tidy -} // namespace clang diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp --- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp @@ -15,7 +15,6 @@ #include "ContainerSizeEmptyCheck.h" #include "ConvertMemberFunctionsToStatic.h" #include "DeleteNullPointerCheck.h" -#include "DeletedDefaultCheck.h" #include "ElseAfterReturnCheck.h" #include "FunctionCognitiveComplexityCheck.h" #include "FunctionSizeCheck.h" @@ -67,8 +66,6 @@ "readability-convert-member-functions-to-static"); CheckFactories.registerCheck( "readability-delete-null-pointer"); - CheckFactories.registerCheck( - "readability-deleted-default"); CheckFactories.registerCheck( "readability-else-after-return"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -112,11 +112,10 @@ function or assignment to ``nullptr``. Added support for pointers to ``std::unique_ptr``. -Deprecated checks -^^^^^^^^^^^^^^^^^ +Removed checks +^^^^^^^^^^^^^^ -- The :doc:`readability-deleted-default - ` check has been deprecated. +- The readability-deleted-default check has been removed. The clang warning `Wdefaulted-function-deleted `_ diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -280,7 +280,6 @@ `readability-container-size-empty `_, "Yes" `readability-convert-member-functions-to-static `_, `readability-delete-null-pointer `_, "Yes" - `readability-deleted-default `_, `readability-else-after-return `_, "Yes" `readability-function-cognitive-complexity `_, `readability-function-size `_, diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability-deleted-default.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-deleted-default.rst deleted file mode 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability-deleted-default.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. title:: clang-tidy - readability-deleted-default - -readability-deleted-default -=========================== - -This check has been deprecated prefer to make use of the `Wdefaulted-function-deleted -`_ -flag. diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-deleted-default.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-deleted-default.cpp deleted file mode 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability-deleted-default.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// RUN: %check_clang_tidy %s readability-deleted-default %t -- -- -fno-ms-compatibility - -class NoDefault { -public: - NoDefault() = delete; - NoDefault(NoDefault &&Other) = delete; - NoDefault(const NoDefault &Other) = delete; -}; - -class MissingEverything { -public: - MissingEverything() = default; - // CHECK-MESSAGES: warning: default constructor is explicitly defaulted but implicitly deleted, probably because a non-static data member or a base class is lacking a default constructor; definition can either be removed or explicitly deleted [readability-deleted-default] - MissingEverything(MissingEverything &&Other) = default; - // CHECK-MESSAGES: warning: move constructor is explicitly defaulted but implicitly deleted, probably because a non-static data member or a base class is neither copyable nor movable; definition can either be removed or explicitly deleted [readability-deleted-default] - MissingEverything(const MissingEverything &Other) = default; - // CHECK-MESSAGES: warning: copy constructor is explicitly defaulted but implicitly deleted, probably because a non-static data member or a base class is not copyable; definition can either be removed or explicitly deleted [readability-deleted-default] - MissingEverything &operator=(MissingEverything &&Other) = default; - // CHECK-MESSAGES: warning: move assignment operator is explicitly defaulted but implicitly deleted, probably because a base class or a non-static data member is not assignable, e.g. because the latter is marked 'const'; definition can either be removed or explicitly deleted [readability-deleted-default] - MissingEverything &operator=(const MissingEverything &Other) = default; - // CHECK-MESSAGES: warning: copy assignment operator is explicitly defaulted but implicitly deleted, probably because a base class or a non-static data member is not assignable, e.g. because the latter is marked 'const'; definition can either be removed or explicitly deleted [readability-deleted-default] - -private: - NoDefault ND; -}; - -class NotAssignable { -public: - NotAssignable(NotAssignable &&Other) = default; - NotAssignable(const NotAssignable &Other) = default; - NotAssignable &operator=(NotAssignable &&Other) = default; - // CHECK-MESSAGES: warning: move assignment operator is explicitly defaulted but implicitly deleted - NotAssignable &operator=(const NotAssignable &Other) = default; - // CHECK-MESSAGES: warning: copy assignment operator is explicitly defaulted but implicitly deleted - -private: - const int I = 0; -}; - -class Movable { -public: - Movable() = default; - Movable(Movable &&Other) = default; - Movable(const Movable &Other) = delete; - Movable &operator=(Movable &&Other) = default; - Movable &operator=(const Movable &Other) = delete; -}; - -class NotCopyable { -public: - NotCopyable(NotCopyable &&Other) = default; - NotCopyable(const NotCopyable &Other) = default; - // CHECK-MESSAGES: warning: copy constructor is explicitly defaulted but implicitly deleted - NotCopyable &operator=(NotCopyable &&Other) = default; - NotCopyable &operator=(const NotCopyable &Other) = default; - // CHECK-MESSAGES: warning: copy assignment operator is explicitly defaulted but implicitly deleted -private: - Movable M; -}; - -template class Templated { -public: - // No warning here, it is a templated class. - Templated() = default; - Templated(Templated &&Other) = default; - Templated(const Templated &Other) = default; - Templated &operator=(Templated &&Other) = default; - Templated &operator=(const Templated &Other) = default; - - class InnerTemplated { - public: - // This class is not in itself templated, but we still don't have warning. - InnerTemplated() = default; - InnerTemplated(InnerTemplated &&Other) = default; - InnerTemplated(const InnerTemplated &Other) = default; - InnerTemplated &operator=(InnerTemplated &&Other) = default; - InnerTemplated &operator=(const InnerTemplated &Other) = default; - - private: - T TVar; - }; - - class InnerNotTemplated { - public: - // This one could technically have warnings, but currently doesn't. - InnerNotTemplated() = default; - InnerNotTemplated(InnerNotTemplated &&Other) = default; - InnerNotTemplated(const InnerNotTemplated &Other) = default; - InnerNotTemplated &operator=(InnerNotTemplated &&Other) = default; - InnerNotTemplated &operator=(const InnerNotTemplated &Other) = default; - - private: - int I; - }; - -private: - const T TVar{}; -}; - -int FunctionWithInnerClass() { - class InnerNotAssignable { - public: - InnerNotAssignable &operator=(InnerNotAssignable &&Other) = default; - // CHECK-MESSAGES: warning: move assignment operator is explicitly defaulted but implicitly deleted - private: - const int I = 0; - }; - return 1; -}; - -template -int TemplateFunctionWithInnerClass() { - class InnerNotAssignable { - public: - InnerNotAssignable &operator=(InnerNotAssignable &&Other) = default; - private: - const T TVar{}; - }; - return 1; -}; - -void Foo() { - Templated V1; - Templated::InnerTemplated V2; - Templated::InnerNotTemplated V3; - TemplateFunctionWithInnerClass(); -}