diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc')
6 files changed, 0 insertions, 288 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index 8e7391ea851..44ea9112ca3 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -11,9 +11,7 @@ add_clang_library(clangTidyMiscModule MacroRepeatedSideEffectsCheck.cpp MiscTidyModule.cpp MisplacedWideningCastCheck.cpp - MoveConstantArgumentCheck.cpp NewDeleteOverloadsCheck.cpp - NoexceptMoveConstructorCheck.cpp NonCopyableObjects.cpp RedundantExpressionCheck.cpp SizeofContainerCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index b38feca72cd..cae52b98330 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -18,9 +18,7 @@ #include "MacroRepeatedSideEffectsCheck.h" #include "MisplacedConstCheck.h" #include "MisplacedWideningCastCheck.h" -#include "MoveConstantArgumentCheck.h" #include "NewDeleteOverloadsCheck.h" -#include "NoexceptMoveConstructorCheck.h" #include "NonCopyableObjects.h" #include "RedundantExpressionCheck.h" #include "SizeofContainerCheck.h" @@ -67,12 +65,8 @@ public: "misc-macro-repeated-side-effects"); CheckFactories.registerCheck<MisplacedWideningCastCheck>( "misc-misplaced-widening-cast"); - CheckFactories.registerCheck<MoveConstantArgumentCheck>( - "misc-move-const-arg"); CheckFactories.registerCheck<NewDeleteOverloadsCheck>( "misc-new-delete-overloads"); - CheckFactories.registerCheck<NoexceptMoveConstructorCheck>( - "misc-noexcept-move-constructor"); CheckFactories.registerCheck<NonCopyableObjectsCheck>( "misc-non-copyable-objects"); CheckFactories.registerCheck<RedundantExpressionCheck>( diff --git a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp b/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp deleted file mode 100644 index 196d982eff1..00000000000 --- a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.cpp +++ /dev/null @@ -1,122 +0,0 @@ -//===--- MoveConstantArgumentCheck.cpp - clang-tidy -----------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "MoveConstantArgumentCheck.h" - -#include "clang/Lex/Lexer.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag, - const SourceManager &SM, - const LangOptions &LangOpts) { - const Expr *Arg = Call->getArg(0); - - CharSourceRange BeforeArgumentsRange = Lexer::makeFileCharRange( - CharSourceRange::getCharRange(Call->getLocStart(), Arg->getLocStart()), - SM, LangOpts); - CharSourceRange AfterArgumentsRange = Lexer::makeFileCharRange( - CharSourceRange::getCharRange(Call->getLocEnd(), - Call->getLocEnd().getLocWithOffset(1)), - SM, LangOpts); - - if (BeforeArgumentsRange.isValid() && AfterArgumentsRange.isValid()) { - Diag << FixItHint::CreateRemoval(BeforeArgumentsRange) - << FixItHint::CreateRemoval(AfterArgumentsRange); - } -} - -void MoveConstantArgumentCheck::storeOptions( - ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "CheckTriviallyCopyableMove", CheckTriviallyCopyableMove); -} - -void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) { - if (!getLangOpts().CPlusPlus) - return; - - auto MoveCallMatcher = - callExpr(callee(functionDecl(hasName("::std::move"))), argumentCountIs(1), - unless(isInTemplateInstantiation())) - .bind("call-move"); - - Finder->addMatcher(MoveCallMatcher, this); - - auto ConstParamMatcher = forEachArgumentWithParam( - MoveCallMatcher, parmVarDecl(hasType(references(isConstQualified())))); - - Finder->addMatcher(callExpr(ConstParamMatcher).bind("receiving-expr"), this); - Finder->addMatcher(cxxConstructExpr(ConstParamMatcher).bind("receiving-expr"), - this); -} - -void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) { - const auto *CallMove = Result.Nodes.getNodeAs<CallExpr>("call-move"); - const auto *ReceivingExpr = Result.Nodes.getNodeAs<Expr>("receiving-expr"); - const Expr *Arg = CallMove->getArg(0); - SourceManager &SM = Result.Context->getSourceManager(); - - CharSourceRange MoveRange = - CharSourceRange::getCharRange(CallMove->getSourceRange()); - CharSourceRange FileMoveRange = - Lexer::makeFileCharRange(MoveRange, SM, getLangOpts()); - if (!FileMoveRange.isValid()) - return; - - bool IsConstArg = Arg->getType().isConstQualified(); - bool IsTriviallyCopyable = - Arg->getType().isTriviallyCopyableType(*Result.Context); - - if (IsConstArg || IsTriviallyCopyable) { - if (const CXXRecordDecl *R = Arg->getType()->getAsCXXRecordDecl()) { - // According to [expr.prim.lambda]p3, "whether the closure type is - // trivially copyable" property can be changed by the implementation of - // the language, so we shouldn't rely on it when issuing diagnostics. - if (R->isLambda()) - return; - // Don't warn when the type is not copyable. - for (const auto *Ctor : R->ctors()) { - if (Ctor->isCopyConstructor() && Ctor->isDeleted()) - return; - } - } - - if (!IsConstArg && IsTriviallyCopyable && !CheckTriviallyCopyableMove) - return; - - bool IsVariable = isa<DeclRefExpr>(Arg); - const auto *Var = - IsVariable ? dyn_cast<DeclRefExpr>(Arg)->getDecl() : nullptr; - auto Diag = diag(FileMoveRange.getBegin(), - "std::move of the %select{|const }0" - "%select{expression|variable %4}1 " - "%select{|of the trivially-copyable type %5 }2" - "has no effect; remove std::move()" - "%select{| or make the variable non-const}3") - << IsConstArg << IsVariable << IsTriviallyCopyable - << (IsConstArg && IsVariable && !IsTriviallyCopyable) << Var - << Arg->getType(); - - ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts()); - } else if (ReceivingExpr) { - auto Diag = diag(FileMoveRange.getBegin(), - "passing result of std::move() as a const reference " - "argument; no move will actually happen"); - - ReplaceCallWithArg(CallMove, Diag, SM, getLangOpts()); - } -} - -} // namespace misc -} // namespace tidy -} // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.h b/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.h deleted file mode 100644 index 85764720652..00000000000 --- a/clang-tools-extra/clang-tidy/misc/MoveConstantArgumentCheck.h +++ /dev/null @@ -1,43 +0,0 @@ -//===--- MoveConstantArgumentCheck.h - clang-tidy -------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace misc { - -/// Find casts of calculation results to bigger type. Typically from int to -/// -/// There is one option: -/// -/// - `CheckTriviallyCopyableMove`: Whether to check for trivially-copyable -// types as their objects are not moved but copied. Enabled by default. -class MoveConstantArgumentCheck : public ClangTidyCheck { -public: - MoveConstantArgumentCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - CheckTriviallyCopyableMove( - Options.get("CheckTriviallyCopyableMove", true)) {} - void storeOptions(ClangTidyOptions::OptionMap &Opts) override; - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; - -private: - const bool CheckTriviallyCopyableMove; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H diff --git a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp b/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp deleted file mode 100644 index 12a360f4ba7..00000000000 --- a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp +++ /dev/null @@ -1,77 +0,0 @@ -//===--- NoexceptMoveConstructorCheck.cpp - clang-tidy---------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "NoexceptMoveConstructorCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" - -using namespace clang::ast_matchers; - -namespace clang { -namespace tidy { -namespace misc { - -void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) { - // Only register the matchers for C++11; the functionality currently does not - // provide any benefit to other languages, despite being benign. - if (!getLangOpts().CPlusPlus11) - return; - - Finder->addMatcher( - cxxMethodDecl(anyOf(cxxConstructorDecl(), hasOverloadedOperatorName("=")), - unless(isImplicit()), unless(isDeleted())) - .bind("decl"), - this); -} - -void NoexceptMoveConstructorCheck::check( - const MatchFinder::MatchResult &Result) { - if (const auto *Decl = Result.Nodes.getNodeAs<CXXMethodDecl>("decl")) { - StringRef MethodType = "assignment operator"; - if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(Decl)) { - if (!Ctor->isMoveConstructor()) - return; - MethodType = "constructor"; - } else if (!Decl->isMoveAssignmentOperator()) { - return; - } - - const auto *ProtoType = Decl->getType()->getAs<FunctionProtoType>(); - - if (isUnresolvedExceptionSpec(ProtoType->getExceptionSpecType())) - return; - - switch (ProtoType->getNoexceptSpec(*Result.Context)) { - case FunctionProtoType::NR_NoNoexcept: - diag(Decl->getLocation(), "move %0s should be marked noexcept") - << MethodType; - // FIXME: Add a fixit. - break; - case FunctionProtoType::NR_Throw: - // Don't complain about nothrow(false), but complain on nothrow(expr) - // where expr evaluates to false. - if (const Expr *E = ProtoType->getNoexceptExpr()) { - if (isa<CXXBoolLiteralExpr>(E)) - break; - diag(E->getExprLoc(), - "noexcept specifier on the move %0 evaluates to 'false'") - << MethodType; - } - break; - case FunctionProtoType::NR_Nothrow: - case FunctionProtoType::NR_Dependent: - case FunctionProtoType::NR_BadNoexcept: - break; - } - } -} - -} // namespace misc -} // namespace tidy -} // namespace clang diff --git a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.h b/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.h deleted file mode 100644 index e6a0ef9284f..00000000000 --- a/clang-tools-extra/clang-tidy/misc/NoexceptMoveConstructorCheck.h +++ /dev/null @@ -1,38 +0,0 @@ -//===--- NoexceptMoveConstructorCheck.h - clang-tidy-------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H - -#include "../ClangTidy.h" - -namespace clang { -namespace tidy { -namespace misc { - -/// The check flags user-defined move constructors and assignment operators not -/// marked with `noexcept` or marked with `noexcept(expr)` where `expr` -/// evaluates to `false` (but is not a `false` literal itself). -/// -/// Move constructors of all the types used with STL containers, for example, -/// need to be declared `noexcept`. Otherwise STL will choose copy constructors -/// instead. The same is valid for move assignment operations. -class NoexceptMoveConstructorCheck : public ClangTidyCheck { -public: - NoexceptMoveConstructorCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} - void registerMatchers(ast_matchers::MatchFinder *Finder) override; - void check(const ast_matchers::MatchFinder::MatchResult &Result) override; -}; - -} // namespace misc -} // namespace tidy -} // namespace clang - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H |