Index: clang-tidy/hicpp/HICPPTidyModule.cpp =================================================================== --- clang-tidy/hicpp/HICPPTidyModule.cpp +++ clang-tidy/hicpp/HICPPTidyModule.cpp @@ -18,9 +18,7 @@ #include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h" #include "../google/DefaultArgumentsCheck.h" #include "../google/ExplicitConstructorCheck.h" -#include "../misc/MoveConstantArgumentCheck.h" #include "../misc/NewDeleteOverloadsCheck.h" -#include "../misc/NoexceptMoveConstructorCheck.h" #include "../misc/StaticAssertCheck.h" #include "../misc/UndelegatedConstructor.h" #include "../modernize/DeprecatedHeadersCheck.h" @@ -31,6 +29,8 @@ #include "../modernize/UseNoexceptCheck.h" #include "../modernize/UseNullptrCheck.h" #include "../modernize/UseOverrideCheck.h" +#include "../performance/MoveConstArgCheck.h" +#include "../performance/NoexceptMoveConstructorCheck.h" #include "../readability/BracesAroundStatementsCheck.h" #include "../readability/FunctionSizeCheck.h" #include "../readability/IdentifierNamingCheck.h" @@ -63,11 +63,11 @@ "hicpp-invalid-access-moved"); CheckFactories.registerCheck( "hicpp-member-init"); - CheckFactories.registerCheck( + CheckFactories.registerCheck( "hicpp-move-const-arg"); CheckFactories.registerCheck( "hicpp-new-delete-operators"); - CheckFactories.registerCheck( + CheckFactories.registerCheck( "hicpp-noexcept-move"); CheckFactories .registerCheck( Index: clang-tidy/misc/CMakeLists.txt =================================================================== --- clang-tidy/misc/CMakeLists.txt +++ clang-tidy/misc/CMakeLists.txt @@ -11,9 +11,7 @@ MacroRepeatedSideEffectsCheck.cpp MiscTidyModule.cpp MisplacedWideningCastCheck.cpp - MoveConstantArgumentCheck.cpp NewDeleteOverloadsCheck.cpp - NoexceptMoveConstructorCheck.cpp NonCopyableObjects.cpp RedundantExpressionCheck.cpp SizeofContainerCheck.cpp Index: clang-tidy/misc/MiscTidyModule.cpp =================================================================== --- clang-tidy/misc/MiscTidyModule.cpp +++ 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 @@ "misc-macro-repeated-side-effects"); CheckFactories.registerCheck( "misc-misplaced-widening-cast"); - CheckFactories.registerCheck( - "misc-move-const-arg"); CheckFactories.registerCheck( "misc-new-delete-overloads"); - CheckFactories.registerCheck( - "misc-noexcept-move-constructor"); CheckFactories.registerCheck( "misc-non-copyable-objects"); CheckFactories.registerCheck( Index: clang-tidy/modernize/PassByValueCheck.cpp =================================================================== --- clang-tidy/modernize/PassByValueCheck.cpp +++ clang-tidy/modernize/PassByValueCheck.cpp @@ -187,7 +187,7 @@ return; // If the parameter is trivial to copy, don't move it. Moving a trivivally - // copyable type will cause a problem with misc-move-const-arg + // copyable type will cause a problem with performance-move-const-arg if (ParamDecl->getType().getNonReferenceType().isTriviallyCopyableType( *Result.Context)) return; Index: clang-tidy/performance/CMakeLists.txt =================================================================== --- clang-tidy/performance/CMakeLists.txt +++ clang-tidy/performance/CMakeLists.txt @@ -7,7 +7,9 @@ InefficientAlgorithmCheck.cpp InefficientStringConcatenationCheck.cpp InefficientVectorOperationCheck.cpp + MoveConstArgCheck.cpp MoveConstructorInitCheck.cpp + NoexceptMoveConstructorCheck.cpp PerformanceTidyModule.cpp TypePromotionInMathFnCheck.cpp UnnecessaryCopyInitialization.cpp Index: clang-tidy/performance/MoveConstArgCheck.h =================================================================== --- clang-tidy/performance/MoveConstArgCheck.h +++ clang-tidy/performance/MoveConstArgCheck.h @@ -1,4 +1,4 @@ -//===--- MoveConstantArgumentCheck.h - clang-tidy -------------------------===// +//===--- MoveConstArgCheck.h - clang-tidy -------------------------===// // // The LLVM Compiler Infrastructure // @@ -14,17 +14,17 @@ namespace clang { namespace tidy { -namespace misc { +namespace performance { -class MoveConstantArgumentCheck : public ClangTidyCheck { +class MoveConstArgCheck : public ClangTidyCheck { public: - MoveConstantArgumentCheck(StringRef Name, ClangTidyContext *Context) + MoveConstArgCheck(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 performance } // namespace tidy } // namespace clang Index: clang-tidy/performance/MoveConstArgCheck.cpp =================================================================== --- clang-tidy/performance/MoveConstArgCheck.cpp +++ clang-tidy/performance/MoveConstArgCheck.cpp @@ -1,4 +1,4 @@ -//===--- MoveConstantArgumentCheck.cpp - clang-tidy -----------------------===// +//===--- MoveConstArgCheck.cpp - clang-tidy -----------------------===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "MoveConstantArgumentCheck.h" +#include "MoveConstArgCheck.h" #include "clang/Lex/Lexer.h" @@ -15,7 +15,7 @@ namespace clang { namespace tidy { -namespace misc { +namespace performance { static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag, const SourceManager &SM, @@ -36,7 +36,7 @@ } } -void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) { +void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; @@ -55,7 +55,7 @@ this); } -void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) { +void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) { const auto *CallMove = Result.Nodes.getNodeAs("call-move"); const auto *ReceivingExpr = Result.Nodes.getNodeAs("receiving-expr"); const Expr *Arg = CallMove->getArg(0); @@ -108,6 +108,6 @@ } } -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang Index: clang-tidy/performance/NoexceptMoveConstructorCheck.h =================================================================== --- clang-tidy/performance/NoexceptMoveConstructorCheck.h +++ clang-tidy/performance/NoexceptMoveConstructorCheck.h @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H #include "../ClangTidy.h" namespace clang { namespace tidy { -namespace misc { +namespace performance { /// The check flags user-defined move constructors and assignment operators not /// marked with `noexcept` or marked with `noexcept(expr)` where `expr` @@ -31,8 +31,8 @@ void check(const ast_matchers::MatchFinder::MatchResult &Result) override; }; -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H Index: clang-tidy/performance/NoexceptMoveConstructorCheck.cpp =================================================================== --- clang-tidy/performance/NoexceptMoveConstructorCheck.cpp +++ clang-tidy/performance/NoexceptMoveConstructorCheck.cpp @@ -15,7 +15,7 @@ namespace clang { namespace tidy { -namespace misc { +namespace performance { void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++11; the functionality currently does not @@ -48,30 +48,30 @@ return; switch (ProtoType->getNoexceptSpec(*Result.Context)) { - case FunctionProtoType::NR_NoNoexcept: - diag(Decl->getLocation(), "move %0s should be marked noexcept") + 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(E)) + break; + diag(E->getExprLoc(), + "noexcept specifier on the move %0 evaluates to 'false'") << 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(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; + } + break; + case FunctionProtoType::NR_Nothrow: + case FunctionProtoType::NR_Dependent: + case FunctionProtoType::NR_BadNoexcept: + break; } } } -} // namespace misc +} // namespace performance } // namespace tidy } // namespace clang Index: clang-tidy/performance/PerformanceTidyModule.cpp =================================================================== --- clang-tidy/performance/PerformanceTidyModule.cpp +++ clang-tidy/performance/PerformanceTidyModule.cpp @@ -16,7 +16,9 @@ #include "InefficientAlgorithmCheck.h" #include "InefficientStringConcatenationCheck.h" #include "InefficientVectorOperationCheck.h" +#include "MoveConstArgCheck.h" #include "MoveConstructorInitCheck.h" +#include "NoexceptMoveConstructorCheck.h" #include "TypePromotionInMathFnCheck.h" #include "UnnecessaryCopyInitialization.h" #include "UnnecessaryValueParamCheck.h" @@ -40,8 +42,12 @@ "performance-inefficient-string-concatenation"); CheckFactories.registerCheck( "performance-inefficient-vector-operation"); + CheckFactories.registerCheck( + "performance-move-const-arg"); CheckFactories.registerCheck( "performance-move-constructor-init"); + CheckFactories.registerCheck( + "performance-noexcept-move-constructor"); CheckFactories.registerCheck( "performance-type-promotion-in-math-fn"); CheckFactories.registerCheck( Index: docs/ReleaseNotes.rst =================================================================== --- docs/ReleaseNotes.rst +++ docs/ReleaseNotes.rst @@ -57,6 +57,12 @@ Improvements to clang-tidy -------------------------- +- The 'misc-move-const-arg' check was renamed to `performance-move-const-arg + `_ + +- The 'misc-noexcept-move-constructor' check was renamed to `performance-noexcept-move-constructor + `_ + - The 'misc-move-constructor-init' check was renamed to `performance-move-constructor-init `_ Index: docs/clang-tidy/checks/hicpp-move-const-arg.rst =================================================================== --- docs/clang-tidy/checks/hicpp-move-const-arg.rst +++ docs/clang-tidy/checks/hicpp-move-const-arg.rst @@ -1,10 +1,10 @@ .. title:: clang-tidy - hicpp-move-const-arg .. meta:: - :http-equiv=refresh: 5;URL=misc-move-const-arg.html + :http-equiv=refresh: 5;URL=performance-move-const-arg.html hicpp-move-const-arg ==================== The `hicpp-move-const-arg` check is an alias, please see -`misc-move-const-arg `_ for more information. +`performance-move-const-arg `_ for more information. It enforces the `rule 17.3.1 `_. Index: docs/clang-tidy/checks/list.rst =================================================================== --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -93,7 +93,7 @@ hicpp-function-size (redirects to readability-function-size) hicpp-invalid-access-moved (redirects to bugprone-use-after-move) hicpp-member-init (redirects to cppcoreguidelines-pro-type-member-init) - hicpp-move-const-arg (redirects to misc-move-const-arg) + hicpp-move-const-arg (redirects to performance-move-const-arg) hicpp-named-parameter (redirects to readability-named-parameter) hicpp-new-delete-operators (redirects to misc-new-delete-overloads) hicpp-no-array-decay (redirects to cppcoreguidelines-pro-bounds-array-to-pointer-decay) @@ -124,9 +124,7 @@ misc-macro-repeated-side-effects misc-misplaced-const misc-misplaced-widening-cast - misc-move-const-arg misc-new-delete-overloads - misc-noexcept-move-constructor misc-non-copyable-objects misc-redundant-expression misc-sizeof-container @@ -182,7 +180,9 @@ performance-inefficient-algorithm performance-inefficient-string-concatenation performance-inefficient-vector-operation + performance-move-const-arg performance-move-constructor-init + performance-noexcept-move-constructor performance-type-promotion-in-math-fn performance-unnecessary-copy-initialization performance-unnecessary-value-param Index: docs/clang-tidy/checks/performance-move-const-arg.rst =================================================================== --- docs/clang-tidy/checks/performance-move-const-arg.rst +++ docs/clang-tidy/checks/performance-move-const-arg.rst @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-move-const-arg +.. title:: clang-tidy - performance-move-const-arg -misc-move-const-arg -=================== +performance-move-const-arg +========================== The check warns Index: docs/clang-tidy/checks/performance-noexcept-move-constructor.rst =================================================================== --- docs/clang-tidy/checks/performance-noexcept-move-constructor.rst +++ docs/clang-tidy/checks/performance-noexcept-move-constructor.rst @@ -1,7 +1,7 @@ -.. title:: clang-tidy - misc-noexcept-move-constructor +.. title:: clang-tidy - performance-noexcept-move-constructor -misc-noexcept-move-constructor -============================== +performance-noexcept-move-constructor +===================================== The check flags user-defined move constructors and assignment operators not Index: test/clang-tidy/modernize-pass-by-value.cpp =================================================================== --- test/clang-tidy/modernize-pass-by-value.cpp +++ test/clang-tidy/modernize-pass-by-value.cpp @@ -202,7 +202,7 @@ template struct array { T A[N]; }; // Test that types that are trivially copyable will not use std::move. This will -// cause problems with misc-move-const-arg, as it will revert it. +// cause problems with performance-move-const-arg, as it will revert it. struct T { T(array a) : a_(a) {} // CHECK-FIXES: T(array a) : a_(a) {} Index: test/clang-tidy/performance-move-const-arg.cpp =================================================================== --- test/clang-tidy/performance-move-const-arg.cpp +++ test/clang-tidy/performance-move-const-arg.cpp @@ -1,23 +1,33 @@ -// RUN: %check_clang_tidy %s misc-move-const-arg %t +// RUN: %check_clang_tidy %s performance-move-const-arg %t namespace std { -template struct remove_reference; +template +struct remove_reference; -template struct remove_reference { typedef _Tp type; }; +template +struct remove_reference { + typedef _Tp type; +}; -template struct remove_reference<_Tp &> { typedef _Tp type; }; +template +struct remove_reference<_Tp &> { + typedef _Tp type; +}; -template struct remove_reference<_Tp &&> { typedef _Tp type; }; +template +struct remove_reference<_Tp &&> { + typedef _Tp type; +}; template constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { return static_cast::type &&>(__t); } -} // namespace std +} // namespace std class A { -public: + public: A() {} A(const A &rhs) {} A(A &&rhs) {} @@ -25,31 +35,36 @@ int f1() { return std::move(42); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'int' has no effect; remove std::move() [misc-move-const-arg] - // CHECK-FIXES: return 42; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of + // the trivially-copyable type 'int' has no effect; remove std::move() + // [performance-move-const-arg] CHECK-FIXES: return 42; } int f2(int x2) { return std::move(x2); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x2' of the trivially-copyable type 'int' - // CHECK-FIXES: return x2; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x2' of + // the trivially-copyable type 'int' CHECK-FIXES: return x2; } int *f3(int *x3) { return std::move(x3); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x3' of the trivially-copyable type 'int *' - // CHECK-FIXES: return x3; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the variable 'x3' of + // the trivially-copyable type 'int *' CHECK-FIXES: return x3; } A f4(A x4) { return std::move(x4); } A f5(const A x5) { return std::move(x5); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [misc-move-const-arg] - // CHECK-FIXES: return x5; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable + // 'x5' has no effect; remove std::move() or make the variable non-const + // [performance-move-const-arg] CHECK-FIXES: return x5; } -template T f6(const T x6) { return std::move(x6); } +template +T f6(const T x6) { + return std::move(x6); +} void f7() { int a = f6(10); } @@ -57,17 +72,20 @@ void f8() { const A a; M1(A b = std::move(a);) - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable 'a' has no effect; remove std::move() or make the variable non-const + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: std::move of the const variable + // 'a' has no effect; remove std::move() or make the variable non-const // CHECK-FIXES: M1(A b = a;) } #define M2(x) std::move(x) int f9() { return M2(1); } -template T f10(const int x10) { +template +T f10(const int x10) { return std::move(x10); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [misc-move-const-arg] - // CHECK-FIXES: return x10; + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable + // 'x10' of the trivially-copyable type 'const int' has no effect; remove + // std::move() [performance-move-const-arg] CHECK-FIXES: return x10; } void f11() { f10(1); @@ -165,7 +183,7 @@ } class MoveOnly { -public: + public: MoveOnly(const MoveOnly &other) = delete; MoveOnly &operator=(const MoveOnly &other) = delete; MoveOnly(MoveOnly &&other) = default; @@ -173,6 +191,4 @@ }; template void Q(T); -void moveOnlyNegatives(MoveOnly val) { - Q(std::move(val)); -} +void moveOnlyNegatives(MoveOnly val) { Q(std::move(val)); } Index: test/clang-tidy/performance-noexcept-move-constructor.cpp =================================================================== --- test/clang-tidy/performance-noexcept-move-constructor.cpp +++ test/clang-tidy/performance-noexcept-move-constructor.cpp @@ -1,8 +1,9 @@ -// RUN: %check_clang_tidy %s misc-noexcept-move-constructor %t +// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t class A { A(A &&); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [misc-noexcept-move-constructor] + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked + // noexcept [performance-noexcept-move-constructor] A &operator=(A &&); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should }; @@ -10,7 +11,8 @@ struct B { static constexpr bool kFalse = false; B(B &&) noexcept(kFalse); - // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [misc-noexcept-move-constructor] + // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move + // constructor evaluates to 'false' [performance-noexcept-move-constructor] }; class OK {}; @@ -24,7 +26,7 @@ public: OK1(); OK1(const OK1 &); - OK1(OK1&&) noexcept; + OK1(OK1 &&) noexcept; OK1 &operator=(OK1 &&) noexcept; void f(); void g() noexcept; @@ -33,7 +35,7 @@ class OK2 { static constexpr bool kTrue = true; -public: + public: OK2(OK2 &&) noexcept(true) {} OK2 &operator=(OK2 &&) noexcept(kTrue) { return *this; } };